2 // Open Service Platform
\r
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
\r
5 // Licensed under the Flora License, Version 1.0 (the License);
\r
6 // you may not use this file except in compliance with the License.
\r
7 // You may obtain a copy of the License at
\r
9 // http://www.tizenopensource.org/license
\r
11 // Unless required by applicable law or agreed to in writing, software
\r
12 // distributed under the License is distributed on an AS IS BASIS,
\r
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
14 // See the License for the specific language governing permissions and
\r
15 // limitations under the License.
\r
17 //==================================================================
\r
18 // APP. Name : WebViewer.cpp
\r
22 //==================================================================
\r
24 #include <FSysPowerManager.h>
\r
25 #include "WebViewer.h"
\r
27 using namespace Osp::Base;
\r
28 using namespace Osp::Base::Utility;
\r
29 using namespace Osp::Graphics;
\r
30 using namespace Osp::Locales;
\r
31 using namespace Osp::System;
\r
32 using namespace Osp::App;
\r
33 using namespace Osp::Ui;
\r
34 using namespace Osp::Ui::Controls;
\r
35 using namespace Osp::Web::Controls;
\r
37 #define AC_BUTTON_WEB_BACK 0x3001
\r
38 #define AC_BUTTON_WEB_FORWARD 0x3002
\r
40 #define AC_BUTTON_WEB_GOTO 0x5001
\r
41 #define AC_BUTTON_WEB_STOP 0x5002
\r
43 #define WEB_URL_PREFIX_HTTP L"http://"
\r
44 #define WEB_URL_EDIT_FIELD_MAX_SIZE 1024
\r
46 WebViewer::WebViewer()
\r
47 : __pMainForm(null), __pWeb(null), __pEdit(null), __pButton(null)
\r
52 WebViewer::~WebViewer()
\r
58 WebViewer::CreateInstance(void)
\r
60 // You can create the instance through another constructor.
\r
61 return new WebViewer();
\r
66 WebViewer::OnAppInitializing(AppRegistry& appRegistry)
\r
68 /////////////////////////////////////////////////////////////////////////////////////
\r
69 //this codes is automatically inserted by Tizen C++ application wizard.
\r
70 Frame* pAppFrame = new Frame();
\r
71 pAppFrame->Construct();
\r
72 AddFrame(*pAppFrame);
\r
73 ////////////////////////////////////////////////////////////////////////////////////
\r
74 result r = E_SUCCESS;
\r
76 r = CreateWebForm();
\r
79 AppLog("CreateMainForm() has failed.\n");
\r
83 // Uncomment the following statement to listen to the screen on/off events.
\r
84 //PowerManager::SetScreenEventListener(*this);
\r
93 WebViewer::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
\r
96 // Deallocate or close any resources still alive.
\r
97 // Save the application's current states, if applicable.
\r
98 // If this method is successful, return true; otherwise, return false.
\r
105 WebViewer::OnForeground(void)
\r
111 WebViewer::OnBackground(void)
\r
117 WebViewer::OnLowMemory(void)
\r
120 // Deallocate as many resources as possible.
\r
125 WebViewer::OnBatteryLevelChanged(BatteryLevel batteryLevel)
\r
130 WebViewer::CreateWebForm(void)
\r
132 result r = E_SUCCESS;
\r
134 WebSetting setting;
\r
139 FooterItem footerItem1;
\r
140 FooterItem footerItem2;
\r
141 IAppFrame* pAppFrame = GetAppFrame();
\r
143 AppResource *pAppResource = Application::GetInstance()->GetAppResource();
\r
144 Bitmap *pBitmap1 = pAppResource->GetBitmapN("/goto.png");
\r
145 Bitmap *pBitmap2 = pAppResource->GetBitmapN("/goto_press.png");
\r
147 if (NULL == pAppFrame)
\r
149 AppLog("GetAppFrame() has failed.\n");
\r
154 __pMainForm = new Form();
\r
155 r = __pMainForm->Construct(FORM_STYLE_NORMAL|FORM_STYLE_INDICATOR|FORM_STYLE_HEADER|FORM_STYLE_FOOTER);
\r
156 TryCatch(r == E_SUCCESS, , "Form Construction() has failed. \n ");
\r
158 __pMainForm->AddOrientationEventListener(*this);
\r
159 __pMainForm->SetOrientation(ORIENTATION_AUTOMATIC);
\r
161 bound = __pMainForm->GetClientAreaBounds();
\r
163 pAppFrame->GetFrame()->AddControl(*__pMainForm);
\r
164 pAppFrame->GetFrame()->SetCurrentForm(*__pMainForm);
\r
167 __pEdit = new EditField();
\r
168 r = __pEdit->Construct(Rectangle(5, 0, bound.width - 72, 63), EDIT_FIELD_STYLE_URL_SMALL, INPUT_STYLE_FULLSCREEN, false, WEB_URL_EDIT_FIELD_MAX_SIZE /*GROUP_STYLE_NONE*/);
\r
169 TryCatch(r == E_SUCCESS, ,"Editfield Construction() has failed.\n ");
\r
170 __pEdit->AddTextEventListener(*this);
\r
171 __pEdit->SetText(Osp::Base::String("http://www.tizen.org"));
\r
173 r = __pMainForm->AddControl(*__pEdit);
\r
174 TryCatch(r == E_SUCCESS, ,"Addcontrol() has failed.\n ");
\r
177 pHeader = __pMainForm->GetHeader();
\r
178 pHeader->SetStyle(HEADER_STYLE_TITLE);
\r
179 pHeader->SetTitleText(L"Web Viewer");
\r
182 pFooter = __pMainForm->GetFooter();
\r
183 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT );
\r
184 pFooter->SetBackButton();
\r
185 pFooter->AddActionEventListener(*this);
\r
186 __pMainForm->SetFormBackEventListener(this);
\r
189 footerItem1.Construct(AC_BUTTON_WEB_BACK);
\r
190 footerItem1.SetText(L"Back");
\r
192 footerItem2.Construct(AC_BUTTON_WEB_FORWARD);
\r
193 footerItem2.SetText(L"Forward");
\r
195 pFooter->AddItem(footerItem1);
\r
196 pFooter->AddItem(footerItem2);
\r
199 __pButton = new Button();
\r
200 r = __pButton->Construct(Rectangle(bound.width - 67,0,67,63),"");
\r
202 __pMainForm->SetBackgroundColor(pFooter->GetColor());
\r
204 __pButton->SetColor(BUTTON_STATUS_NORMAL ,pFooter->GetColor());
\r
205 __pButton->SetColor(BUTTON_STATUS_PRESSED ,pFooter->GetColor());
\r
207 __pButton->SetActionId(AC_BUTTON_WEB_GOTO);
\r
208 __pButton->SetNormalBackgroundBitmap(*pBitmap1);
\r
209 __pButton->SetPressedBackgroundBitmap(*pBitmap2);
\r
210 __pButton->AddActionEventListener(*this);
\r
212 r = __pMainForm->AddControl(*__pButton);
\r
213 TryCatch(r == E_SUCCESS, ,"Addcontrol() has failed.\n ");
\r
216 __pWeb = new Web();
\r
218 bound = __pMainForm->GetClientAreaBounds();
\r
219 r = __pWeb->Construct(Rectangle(0,66, bound.width, bound.height - 66));
\r
220 TryCatch(r == E_SUCCESS, ,"Web Construct() has failed.\n ");
\r
222 r = __pMainForm->AddControl(*__pWeb);
\r
223 TryCatch(r == E_SUCCESS, ,"Addcontrol() has failed.\n ");
\r
225 setting.SetInputStyle(INPUT_STYLE_OVERLAY);
\r
226 r = __pWeb->SetSetting(setting);
\r
227 TryCatch(r == E_SUCCESS, ,"SetSetting() has failed.\n ");
\r
229 __pWeb->SetLoadingListener(this);
\r
230 __pWeb->SetWebKeypadEventListener(this);
\r
231 __pWeb->SetWebUiEventListener(this);
\r
233 __pWeb->SetFocus();
\r
241 AppLog("Error = %s\n", GetErrorMessage(r));
\r
250 WebViewer::OnActionPerformed(const Control& source, int actionId)
\r
255 case AC_BUTTON_WEB_BACK:
\r
258 case AC_BUTTON_WEB_FORWARD:
\r
259 __pWeb->GoForward();
\r
261 case AC_BUTTON_WEB_GOTO :
\r
262 url = __pEdit->GetText();
\r
263 __pWeb->LoadUrl(GetValidUrl(url));
\r
264 __pMainForm->RequestRedraw (true);
\r
266 case AC_BUTTON_WEB_STOP :
\r
267 __pWeb->StopLoading();
\r
278 WebViewer::OnOrientationChanged(const Control &source, OrientationStatus orientationStatus)
\r
280 Rectangle bound = __pMainForm->GetClientAreaBounds();
\r
282 __pEdit->SetBounds(Rectangle(5, 0, bound.width - 72, 63));
\r
283 __pButton->SetBounds(Rectangle(bound.width - 67,0,67,63));
\r
285 if(__pWeb->IsVisible())
\r
286 __pWeb->SetBounds(Rectangle(0,66, bound.width, bound.height - 66));
\r
288 __pMainForm->Draw();
\r
292 WebViewer::OnTextValueChangeCanceled ( const Osp::Ui::Control & source )
\r
294 __pMainForm->SetFocus();
\r
298 WebViewer::OnTextValueChanged ( const Osp::Ui::Control & source )
\r
300 __pMainForm->SetFocus();
\r
304 WebViewer::OnScreenOn (void)
\r
307 // Get the released resources or resume the operations that were paused or stopped in OnScreenOff().
\r
311 WebViewer::OnScreenOff (void)
\r
314 // Unless there is a strong reason to do otherwise, release resources (such as 3D, media, and sensors) to allow the device to enter the sleep mode to save the battery.
\r
315 // Invoking a lengthy asynchronous method within this listener method can be risky, because it is not guaranteed to invoke a callback before the device enters the sleep mode.
\r
316 // Similarly, do not perform lengthy operations in this listener method. Any operation must be a quick one.
\r
320 WebViewer::GetValidUrl(Osp::Base::String& url)
\r
323 String absoluteUrl = url;
\r
326 if (uri.GetScheme() == L"")
\r
328 absoluteUrl.Insert(WEB_URL_PREFIX_HTTP, 0);
\r
330 return absoluteUrl;
\r
334 WebViewer::CheckURLType(const Osp::Base::String& url)
\r
336 result r = E_SUCCESS;
\r
337 int index_pos = -1;
\r
339 r = url.IndexOf(':',0, index_pos);
\r
347 WebViewer::OnHttpAuthenticationRequestedN(const Osp::Base::String& host, const Osp::Base::String& realm, const Osp::Web::Controls::AuthenticationChallenge& authentication)
\r
353 WebViewer::OnHttpAuthenticationCanceled()
\r
359 WebViewer::OnLoadingStarted(void)
\r
361 SetButtonCancelImage();
\r
365 WebViewer::OnLoadingCanceled()
\r
367 SetButtonGotoImage();
\r
371 WebViewer::OnLoadingErrorOccurred(LoadingErrorType error, const String& reason)
\r
373 Osp::Ui::Controls::MessageBox msgBox;
\r
374 int modalresult = 0;
\r
375 Osp::Base::String errReason;
\r
379 case WEB_REQUEST_TIMEOUT:
\r
380 errReason = Osp::Base::String(L"Request timeout");
\r
382 case WEB_NO_CONNECTION:
\r
383 errReason = Osp::Base::String(L"Network is not in service");
\r
385 case WEB_MIME_NOT_SUPPORTED:
\r
386 errReason = Osp::Base::String(L"The content type is not supported");
\r
389 errReason = Osp::Base::String(L"The url is invalid");
\r
391 case WEB_HTTP_RESPONSE:
\r
392 errReason = Osp::Base::String(L"HTTP response");
\r
394 case WEB_OUT_OF_MEMORY:
\r
395 errReason = Osp::Base::String(L"Page Too Large");
\r
397 case WEB_REQUEST_MAX_EXCEEDED:
\r
398 errReason = Osp::Base::String(L"Request Max Exceeded");
\r
400 case WEB_ERROR_UNKNOWN:
\r
402 errReason = Osp::Base::String(L"An Unknown error");
\r
406 msgBox.Construct(L"LOADING ERROR TYPE", errReason, MSGBOX_STYLE_NONE, 3000);
\r
407 // Call ShowAndWait - draw, show itself and process events
\r
408 msgBox.ShowAndWait(modalresult);
\r
409 SetButtonGotoImage();
\r
413 WebViewer::OnLoadingCompleted()
\r
415 SetButtonGotoImage();
\r
419 WebViewer::OnEstimatedProgress(int progress)
\r
425 WebViewer::OnPageTitleReceived(const Osp::Base::String& title)
\r
431 WebViewer::OnLoadingRequested(const Osp::Base::String& url, WebNavigationType type)
\r
439 WebViewer::OnWebDataReceived(const Osp::Base::String& mime, const Osp::Net::Http::HttpHeader& header)
\r
441 return WEB_DECISION_CONTINUE;
\r
445 WebViewer::OnFormBackRequested(Osp::Ui::Controls::Form& source)
\r
447 AppLog("OnFormBackRequested.");
\r
452 WebViewer::OnWebPageBlockSelected(Osp::Web::Controls::Web& source, Osp::Graphics::Point& startPoint, Osp::Graphics::Point& endPoint)
\r
458 WebViewer::OnWebWindowCloseRequested(Osp::Web::Controls::Web& source)
\r
463 Osp::Web::Controls::Web*
\r
464 WebViewer::OnWebWindowCreateRequested()
\r
470 WebViewer::OnWebPageShowRequested(Osp::Web::Controls::Web& source)
\r
472 AppLog("OnWebPageShowRequested");
\r
473 result r = E_SUCCESS;
\r
475 r = __pEdit->SetText(__pWeb->GetUrl());
\r
476 TryReturn(r == E_SUCCESS, , "Fail to update URL in the EditField.");
\r
478 __pMainForm->RequestRedraw (true);
\r
482 WebViewer::OnWebKeypadWillOpen(Osp::Web::Controls::Web& source)
\r
484 Rectangle bound = __pMainForm->GetClientAreaBounds();
\r
485 AppLog("OnWebKeypadWillOpen.");
\r
487 if(source.IsVisible())
\r
488 source.SetSize(bound.width, bound.height-66);
\r
493 WebViewer::OnWebKeypadOpened(Osp::Web::Controls::Web& source)
\r
495 AppLog("OnWebKeypadOpened.");
\r
500 WebViewer::OnWebKeypadClosed(Osp::Web::Controls::Web& source)
\r
502 AppLog("OnWebKeypadClosed.");
\r
503 Rectangle bound = __pMainForm->GetClientAreaBounds();
\r
504 source.SetSize(bound.width, bound.height-66);
\r
508 WebViewer::SetButtonGotoImage()
\r
510 AppResource *pAppResource = Application::GetInstance()->GetAppResource();
\r
511 Bitmap *pBitmap1 = pAppResource->GetBitmapN("/goto.png");
\r
512 Bitmap *pBitmap2 = pAppResource->GetBitmapN("/goto_press.png");
\r
514 __pButton->SetNormalBackgroundBitmap(*pBitmap1);
\r
515 __pButton->SetPressedBackgroundBitmap(*pBitmap2);
\r
516 __pButton->SetActionId(AC_BUTTON_WEB_GOTO);
\r
525 WebViewer::SetButtonCancelImage()
\r
527 AppResource *pAppResource = Application::GetInstance()->GetAppResource();
\r
528 Bitmap *pBitmap1 = pAppResource->GetBitmapN("/cancel.png");
\r
529 Bitmap *pBitmap2 = pAppResource->GetBitmapN("/cancel_press.png");
\r
531 __pButton->SetNormalBackgroundBitmap(*pBitmap1);
\r
532 __pButton->SetPressedBackgroundBitmap(*pBitmap2);
\r
533 __pButton->SetActionId(AC_BUTTON_WEB_STOP);
\r