bada tutorial.web

17
Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 1 bada 1.1. 0 Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. bada Tutorial: W eb

Upload: matteo425

Post on 09-Apr-2018

233 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Bada Tutorial.web

8/8/2019 Bada Tutorial.web

http://slidepdf.com/reader/full/bada-tutorialweb 1/17

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 1

bada 1.1.0Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved.

bada Tutorial:

Web

Page 2: Bada Tutorial.web

8/8/2019 Bada Tutorial.web

http://slidepdf.com/reader/full/bada-tutorialweb 2/17

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 2

Contents• Essential Classes• Relationships between Classes• Overview• Web Control

– Example: Load a Web Page – Example: Download Web Content – Example: JavaScript Interaction

• FAQ• Review• Answers

Page 3: Bada Tutorial.web

8/8/2019 Bada Tutorial.web

http://slidepdf.com/reader/full/bada-tutorialweb 3/17

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 3

Essential ClassesOsp::Web

Osp::Web::Controls

Feature Provided by

Contains HistoryItems to give you the complete browsing history. WebHistory

Stores the URL and title of a visited page. HistoryItem

Feature Provided by

Provides browser functionality. Web

Configures the Web browser engine. WebSetting

Provides a list of pages the Web control has visited. PageNavigationList

Provides methods for loading events. ILoadingListener

Provides methods for downloading data. IWebDownloadListener

Handles HTTP authentication. AuthenticationChallenge

Retrieves HTML element information from a hit test event. HitElementResult

Page 4: Bada Tutorial.web

8/8/2019 Bada Tutorial.web

http://slidepdf.com/reader/full/bada-tutorialweb 4/17

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 4

Relationships between Classes

Page 5: Bada Tutorial.web

8/8/2019 Bada Tutorial.web

http://slidepdf.com/reader/full/bada-tutorialweb 5/17

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 5

Overview• The Web namespace lets you track browsing history using the

Osp::Web::WebHistory class.• The Osp::Web::Controls::Web class provides the Internet

browser control that can be placed in an application GUI to: – Embed a turn-key Internet browser.

• Add a Web browser to your application justas you do any other UI control.

– Easily download and handle content.• Intercept and handle requests and responses.

– Run JavaScript inside the browser.• Run JavaScript in a Web page

with the EvaluateJavascriptN() method.• Web control is based on Webkit ( http://webkit.org/ ).

Web class in an application

Page 6: Bada Tutorial.web

8/8/2019 Bada Tutorial.web

http://slidepdf.com/reader/full/bada-tutorialweb 6/17

Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 6

Web Control (1/2)

With Web::Controls classes you can: – Handle events. – Authenticate with servers. – Get the following information about elements that have been clicked:

<tag attribute=“value”>character data</tag>• Tag name• Attributes• Character data• Images• URL

– Handle content by MIME type. – Handle loading events. – Download content directly to consume in your application.

Page 7: Bada Tutorial.web

8/8/2019 Bada Tutorial.web

http://slidepdf.com/reader/full/bada-tutorialweb 7/17Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 7

Web Control (2/2)

The Web::Controls namespace provides two listeners to handlebrowser events.1. ILoadingListener

– You can define custom actions by implementing this interface. – The browser engine defaults to its own actions if none are defined.

2. IWebDownloadListener – You can use the listener to handle downloads. – You can receive data incrementally. – You can decide in ILoadingListener which MIME types are routed

to this listener. –

This listener is useful when content is not supported by the frameworkand needs to be handled by the application, for example, proprietaryfile formats.

Page 8: Bada Tutorial.web

8/8/2019 Bada Tutorial.web

http://slidepdf.com/reader/full/bada-tutorialweb 8/17Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 8

Example: Load a Web Page

Load and display a Web page. – Open \<BADA_SDK_HOME>\Examples

\Web\src\DrawWebContent.cpp , LoadUrl()

1. Construct a Web:Web::Construct()

2. Attach to a parent control:Control::AddControl()

3. Load URL:Web::LoadUrl(url)

4. The Web page displays in the Web browser control.

ApplicationApplication Content

AppContent

Web

Page 9: Bada Tutorial.web

8/8/2019 Bada Tutorial.web

http://slidepdf.com/reader/full/bada-tutorialweb 9/17Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 9

Example: Download Web Content (1/3)• When a URL loads, the

OnWebDataReceived() event fires,letting you decide how to handlethe data.

• WEB_DECISION_DOWNLOADpasses control to theOnWebChunkedDataReceived()event handler so you can processthe download manually.

• OnWebDatadownloadComplete()signals that the download is finished.

Web Browser Control

Load a URL

OnWebDataReceived()

ReturnWEB_DECISION_DOWNLOAD to

manually handle download

OnWebChunkedDataReceived()

Save or handle data

OnWebDataDownloadComplete()

Download is finished

Page 10: Bada Tutorial.web

8/8/2019 Bada Tutorial.web

http://slidepdf.com/reader/full/bada-tutorialweb 10/17Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 10

Example: Download Web Content (2/3)

Download content from Web. – Open \<BADA_SDK_HOME>\Examples\Web\src\

DownloadWebContent.cpp , DownloadData(),OnWebChunkedDataReceived(),OnWebDataDownloadCompleted()

1. Construct a Web:Web::Construct()

2. Attach to a parent control:Control::AddControl()

3. Set a loading listener:

Web::SetLoadingListener()4. Set a download listener:

Web::SetDownloadListener()5. Load a URL:

Web::LoadUrl()

Page 11: Bada Tutorial.web

8/8/2019 Bada Tutorial.web

http://slidepdf.com/reader/full/bada-tutorialweb 11/17Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 11

Example: Download Web Content (3/3)6. When ILoadingListener::OnWebDataReceived() is called,

return WEB_DECISION_DOWNLOAD.7. Data with the URL is routed to

IWebDownloadListener::OnWebChunkedDataReceived()whenever data is received.

8. When the download is finished, IWebDownloadListener::

OnWebDataDownloadCompleted() is called.

Page 12: Bada Tutorial.web

8/8/2019 Bada Tutorial.web

http://slidepdf.com/reader/full/bada-tutorialweb 12/17Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 12

Example: JavaScript Interaction (1/2)

Control Google Map with JavaScript. – Open \<BADA_SDK_HOME>\Examples\Web\

src\EvalJavaScript.cpp , SetZoomLevel()

1. Construct and prepare a Web control:Web::Construct()

2. Load the URL with the HTML file:Web::LoadUrl(L"\Res\Map.html");

3. Run JavaScript:Web::EvaluateJavascriptN(L"map.setZoom(10);");

4. Redraw the page at the specified zoom level.

Page 13: Bada Tutorial.web

8/8/2019 Bada Tutorial.web

http://slidepdf.com/reader/full/bada-tutorialweb 13/17Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 13

Example: JavaScript Interaction (2/2)

The following snippet shows a sample of the Map.html file and how toprocess JavaScript:

<html><head><meta name="viewport" content="initial-scale=1.0, user-scalable=no" /><script type="text/javascript"src="http://maps.google.com/maps/api/js?sensor=false"></script><script type="text/javascript">

var map;function initialize() {

var latlng = new google.maps.LatLng(-34.397, 150.644);var myOptions = {

zoom: 8,disableDefaultUI: true,center: latlng,mapTypeId: google.maps.MapTypeId.ROADMAP

};

map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);}</script></head><body onload="initialize()">

<div id="map_canvas" style="width:100%; height:100%"></div></body></html>

Page 14: Bada Tutorial.web

8/8/2019 Bada Tutorial.web

http://slidepdf.com/reader/full/bada-tutorialweb 14/17Copyright © 2010 Samsung Electronics Co., Ltd. All rights reserved. 14

FAQ

Why am I unable to load a page into a Web browser control? – Most likely your network configuration is not set properly.

To check that the configuration is valid, see Proxy Address Setting in theCommunication tutorial.

Page 15: Bada Tutorial.web

8/8/2019 Bada Tutorial.web

http://slidepdf.com/reader/full/bada-tutorialweb 15/17

Page 16: Bada Tutorial.web

8/8/2019 Bada Tutorial.web

http://slidepdf.com/reader/full/bada-tutorialweb 16/17

Page 17: Bada Tutorial.web

8/8/2019 Bada Tutorial.web

http://slidepdf.com/reader/full/bada-tutorialweb 17/17