Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / xwalk / application / browser / application_tizen.cc
index ff53eee..ddf9e17 100644 (file)
 #include "content/public/browser/web_contents.h"
 #include "content/public/browser/render_process_host.h"
 #include "content/public/browser/screen_orientation_dispatcher_host.h"
+#include "content/public/browser/screen_orientation_delegate.h"
 #include "content/public/browser/screen_orientation_provider.h"
 
-#include "xwalk/runtime/browser/runtime_context.h"
+#include "xwalk/runtime/browser/xwalk_browser_context.h"
 #include "xwalk/runtime/browser/runtime_url_request_context_getter.h"
 #include "xwalk/runtime/browser/ui/native_app_window.h"
 #include "xwalk/runtime/browser/ui/native_app_window_tizen.h"
@@ -87,59 +88,63 @@ blink::WebScreenOrientationLockType GetDefaultOrientation(
   }
 }
 
-class ScreenOrientationProviderTizen :
-    public content::ScreenOrientationProvider {
+class ScreenOrientationDelegateTizen :
+    public content::ScreenOrientationDelegate {
  public:
-  ScreenOrientationProviderTizen(
+  ScreenOrientationDelegateTizen(
       const base::WeakPtr<Application>& app,
       content::ScreenOrientationDispatcherHost* dispatcher)
       : app_(app),
-        dispatcher_(dispatcher),
-        request_id_(0) {
+        dispatcher_(dispatcher) {
     DCHECK(dispatcher_);
   }
 
-  virtual void LockOrientation(
-      int request_id,
-      blink::WebScreenOrientationLockType lock) OVERRIDE {
+  bool FullScreenRequired(
+      content::WebContents* web_contents) override {
     if (!app_) {
-      dispatcher_->NotifyLockError(
-          request_id,
-          blink::WebLockOrientationError::WebLockOrientationErrorNotAvailable);
+      LOG(ERROR) << "Invalid app error";
+      return false;
+    }
+    return app_->IsFullScreenRequired();
+  }
+
+  void Lock(blink::WebScreenOrientationLockType lock) override {
+    if (!app_) {
+      LOG(ERROR) << "Invalid app error";
       return;
     }
-    request_id_ = request_id;
-    const std::set<Runtime*>& runtimes = app_->runtimes();
+    const std::vector<Runtime*>& runtimes = app_->runtimes();
     DCHECK(!runtimes.empty());
     // FIXME: Probably need better alignment with
     // https://w3c.github.io/screen-orientation/#screen-orientation-lock-lifetime
-    std::set<Runtime*>::iterator it = runtimes.begin();
-    for (; it != runtimes.end(); ++it) {
+    for (auto it = runtimes.begin(); it != runtimes.end(); ++it) {
       NativeAppWindow* window = (*it)->window();
       if (window && window->IsActive()) {
         ToNativeAppWindowTizen(window)->LockOrientation(lock);
         break;
       }
     }
+    int request_id = app_->GetRenderProcessHostID();
     dispatcher_->NotifyLockSuccess(request_id);
   }
 
-  virtual void UnlockOrientation() OVERRIDE {
-    LockOrientation(request_id_, GetDefaultOrientation(app_));
+  bool ScreenOrientationProviderSupported() override {
+    return true;
   }
 
-  virtual void OnOrientationChange() OVERRIDE {}
+  void Unlock() override {
+    Lock(GetDefaultOrientation(app_));
+  }
 
  private:
   base::WeakPtr<Application> app_;
   content::ScreenOrientationDispatcherHost* dispatcher_;
-  int request_id_;
 };
 
 ApplicationTizen::ApplicationTizen(
     scoped_refptr<ApplicationData> data,
-    RuntimeContext* runtime_context)
-    : Application(data, runtime_context),
+    XWalkBrowserContext* browser_context)
+    : Application(data, browser_context),
 #if defined(OS_TIZEN_MOBILE)
       root_window_(NULL),
 #endif
@@ -148,7 +153,7 @@ ApplicationTizen::ApplicationTizen(
   ui::PlatformEventSource::GetInstance()->AddPlatformEventObserver(this);
 #endif
   cookie_manager_ = scoped_ptr<CookieManager>(
-      new CookieManager(id(), runtime_context_));
+      new CookieManager(id(), browser_context_));
 }
 
 ApplicationTizen::~ApplicationTizen() {
@@ -159,8 +164,7 @@ ApplicationTizen::~ApplicationTizen() {
 
 void ApplicationTizen::Hide() {
   DCHECK(!runtimes_.empty());
-  std::set<Runtime*>::iterator it = runtimes_.begin();
-  for (; it != runtimes_.end(); ++it) {
+  for (auto it = runtimes_.begin(); it != runtimes_.end(); ++it) {
     if ((*it)->window())
       (*it)->window()->Minimize();
   }
@@ -203,11 +207,10 @@ bool ApplicationTizen::Launch(const LaunchParams& launch_params) {
 
     content::ScreenOrientationDispatcherHost* host =
         web_contents_->GetScreenOrientationDispatcherHost();
-    content::ScreenOrientationProvider* provider =
-        new ScreenOrientationProviderTizen(GetWeakPtr(), host);
-    host->SetProvider(provider);
-
-    provider->LockOrientation(0, GetDefaultOrientation(GetWeakPtr()));
+    content::ScreenOrientationDelegate* delegate =
+        new ScreenOrientationDelegateTizen(GetWeakPtr(), host);
+    content::ScreenOrientationProvider::SetDelegate(delegate);
+    delegate->Lock(GetDefaultOrientation(GetWeakPtr()));
     return true;
   }
   return false;
@@ -237,8 +240,7 @@ void ApplicationTizen::Suspend() {
   render_process_host_->Send(new ViewMsg_SuspendJSEngine(true));
 
   DCHECK(!runtimes_.empty());
-  std::set<Runtime*>::iterator it = runtimes_.begin();
-  for (; it != runtimes_.end(); ++it) {
+  for (auto it = runtimes_.begin(); it != runtimes_.end(); ++it) {
     if ((*it)->web_contents())
       (*it)->web_contents()->WasHidden();
   }
@@ -253,8 +255,7 @@ void ApplicationTizen::Resume() {
   render_process_host_->Send(new ViewMsg_SuspendJSEngine(false));
 
   DCHECK(!runtimes_.empty());
-  std::set<Runtime*>::iterator it = runtimes_.begin();
-  for (; it != runtimes_.end(); ++it) {
+  for (auto it = runtimes_.begin(); it != runtimes_.end(); ++it) {
     if ((*it)->web_contents())
       (*it)->web_contents()->WasShown();
   }
@@ -286,7 +287,7 @@ void ApplicationTizen::DidProcessEvent(
   if (info && !info->hwkey_enabled())
     return;
 
-  for (std::set<xwalk::Runtime*>::iterator it = runtimes_.begin();
+  for (auto it = runtimes_.begin();
       it != runtimes_.end(); ++it) {
     (*it)->web_contents()->GetRenderViewHost()->Send(new ViewMsg_HWKeyPressed(
         (*it)->web_contents()->GetRoutingID(), key_event->key_code()));
@@ -303,18 +304,18 @@ void ApplicationTizen::SetUserAgentString(
   cookie_manager_->SetUserAgentString(render_process_host_, user_agent_string);
 }
 
-void ApplicationTizen::OnRuntimeAdded(Runtime* runtime) {
+void ApplicationTizen::OnNewRuntimeAdded(Runtime* runtime) {
   DCHECK(runtime);
-  Application::OnRuntimeAdded(runtime);
+  Application::OnNewRuntimeAdded(runtime);
 #if defined(OS_TIZEN_MOBILE)
   if (root_window_ && runtimes_.size() > 1)
       root_window_->Show();
 #endif
 }
 
-void ApplicationTizen::OnRuntimeRemoved(Runtime* runtime) {
+void ApplicationTizen::OnRuntimeClosed(Runtime* runtime) {
   DCHECK(runtime);
-  Application::OnRuntimeRemoved(runtime);
+  Application::OnRuntimeClosed(runtime);
 #if defined(OS_TIZEN_MOBILE)
   if (runtimes_.empty() && root_window_) {
     root_window_->Close();