Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / xwalk / extensions / renderer / xwalk_extension_renderer_controller.cc
index 7536ea0..25929d7 100644 (file)
 #include "xwalk/extensions/renderer/xwalk_module_system.h"
 #include "xwalk/extensions/renderer/xwalk_v8tools_module.h"
 
+#if defined(OS_TIZEN)
+#include "xwalk/application/common/constants.h"
+#endif
+
 namespace xwalk {
 namespace extensions {
 
@@ -35,7 +39,6 @@ XWalkExtensionRendererController::XWalkExtensionRendererController(
       delegate_(delegate) {
   content::RenderThread* thread = content::RenderThread::Get();
   thread->AddObserver(this);
-
   IPC::SyncChannel* browser_channel = thread->GetChannel();
   SetupBrowserProcessClient(browser_channel);
 
@@ -71,10 +74,28 @@ void CreateExtensionModules(XWalkExtensionClient* client,
   }
 }
 
+#if defined(OS_TIZEN)
+void CreateExtensionModulesWithoutDeviceAPI(XWalkExtensionClient* client,
+                                            XWalkModuleSystem* module_system) {
+  const XWalkExtensionClient::ExtensionAPIMap& extensions =
+      client->extension_apis();
+  XWalkExtensionClient::ExtensionAPIMap::const_iterator it = extensions.begin();
+  for (; it != extensions.end(); ++it) {
+    XWalkExtensionClient::ExtensionCodePoints* codepoint = it->second;
+    if (codepoint->api.empty() || it->first.find("tizen") == 0)
+      continue;
+    scoped_ptr<XWalkExtensionModule> module(
+        new XWalkExtensionModule(client, module_system,
+                                 it->first, codepoint->api));
+    module_system->RegisterExtensionModule(module.Pass(),
+                                           codepoint->entry_points);
+  }
+}
+#endif
 }  // namespace
 
 void XWalkExtensionRendererController::DidCreateScriptContext(
-    WebKit::WebFrame* frame, v8::Handle<v8::Context> context) {
+    blink::WebFrame* frame, v8::Handle<v8::Context> context) {
   XWalkModuleSystem* module_system = new XWalkModuleSystem(context);
   XWalkModuleSystem::SetModuleSystemInContext(
       scoped_ptr<XWalkModuleSystem>(module_system), context);
@@ -91,15 +112,26 @@ void XWalkExtensionRendererController::DidCreateScriptContext(
                          module_system);
 
   if (external_extensions_client_) {
+#if defined(OS_TIZEN)
+    // On Tizen platform, only local pages can access to device APIs.
+    GURL url = static_cast<GURL>(frame->document().url());
+    if (!url.SchemeIs(xwalk::application::kApplicationScheme) &&
+        !url.SchemeIsFile())
+      CreateExtensionModulesWithoutDeviceAPI(external_extensions_client_.get(),
+                                             module_system);
+    else
+      CreateExtensionModules(external_extensions_client_.get(), module_system);
+#else
     CreateExtensionModules(external_extensions_client_.get(),
                            module_system);
+#endif
   }
 
   module_system->Initialize();
 }
 
 void XWalkExtensionRendererController::WillReleaseScriptContext(
-    WebKit::WebFrame* frame, v8::Handle<v8::Context> context) {
+    blink::WebLocalFrame* frame, v8::Handle<v8::Context> context) {
   v8::Context::Scope contextScope(context);
   XWalkModuleSystem::ResetModuleSystemFromContext(context);
 }
@@ -127,10 +159,10 @@ void XWalkExtensionRendererController::SetupExtensionProcessClient(
   // FIXME(cmarcelo): Need to account for failure in creating the channel.
 
   external_extensions_client_.reset(new XWalkExtensionClient);
-  extension_process_channel_.reset(new IPC::SyncChannel(handle,
+  extension_process_channel_ = IPC::SyncChannel::Create(handle,
       IPC::Channel::MODE_CLIENT, external_extensions_client_.get(),
       content::RenderThread::Get()->GetIOMessageLoopProxy(), true,
-      &shutdown_event_));
+      &shutdown_event_);
 
   external_extensions_client_->Initialize(extension_process_channel_.get());
 }