|did-frame-rendered| used for optimize launching time
[platform/framework/web/crosswalk-tizen.git] / atom / browser / api / atom_api_web_contents.cc
index 7e3e176..fccae5a 100644 (file)
@@ -77,6 +77,7 @@
 #include "net/url_request/url_request_context.h"
 #include "third_party/WebKit/public/platform/WebInputEvent.h"
 #include "third_party/WebKit/public/web/WebFindOptions.h"
+#include "tizen/common/env_variables.h"
 #include "ui/display/screen.h"
 
 #if defined(USE_EFL)
@@ -282,7 +283,8 @@ WebContents::WebContents(v8::Isolate* isolate,
       type_(type),
       request_id_(0),
       background_throttling_(true),
-      enable_devtools_(true) {
+      enable_devtools_(true),
+      notify_ready_state_(false) {
   if (type == REMOTE) {
     web_contents->SetUserAgentOverride(GetBrowserContext()->GetUserAgent());
     Init(isolate);
@@ -466,7 +468,8 @@ void WebContents::WebContentsCreated(content::WebContents* source_contents,
                                      const std::string& frame_name,
                                      const GURL& target_url,
                                      content::WebContents* new_contents) {
-  v8::Locker locker(isolate());
+  if (!::tizen::is_single_process)
+    v8::Locker locker(isolate());
   v8::HandleScope handle_scope(isolate());
   auto api_web_contents = CreateFrom(isolate(), new_contents, BROWSER_WINDOW);
   Emit("-web-contents-created", api_web_contents, target_url, frame_name);
@@ -478,7 +481,8 @@ void WebContents::AddNewContents(content::WebContents* source,
                                  const gfx::Rect& initial_rect,
                                  bool user_gesture,
                                  bool* was_blocked) {
-  v8::Locker locker(isolate());
+  if (!::tizen::is_single_process)
+    v8::Locker locker(isolate());
   v8::HandleScope handle_scope(isolate());
   auto api_web_contents = CreateFrom(isolate(), new_contents);
   if (Emit("-add-new-contents", api_web_contents, disposition, user_gesture,
@@ -630,7 +634,8 @@ void WebContents::FindReply(content::WebContents* web_contents,
   if (!final_update)
     return;
 
-  v8::Locker locker(isolate());
+  if (!::tizen::is_single_process)
+    v8::Locker locker(isolate());
   v8::HandleScope handle_scope(isolate());
   mate::Dictionary result = mate::Dictionary::CreateEmpty(isolate());
   result.Set("requestId", request_id);
@@ -685,6 +690,7 @@ void WebContents::RenderViewCreated(content::RenderViewHost* render_view_host) {
       render_view_host->GetRoutingID());
   if (impl)
     impl->disable_hidden_ = !background_throttling_;
+  atom::Browser::Get()->RenderViewCreated(render_view_host);
 }
 
 void WebContents::RenderViewDeleted(content::RenderViewHost* render_view_host) {
@@ -741,7 +747,15 @@ void WebContents::DidFailLoad(content::RenderFrameHost* render_frame_host,
   Emit("did-fail-load", error_code, error_description, url, is_main_frame);
 }
 
+void WebContents::DidRenderFrame() {
+  if (!notify_ready_state_) {
+    notify_ready_state_ = true;
+    Emit("did-frame-rendered");
+  }
+}
+
 void WebContents::DidStartLoading() {
+  notify_ready_state_ = false;
 #if defined(OS_TIZEN)
   if (owner_window() && !owner_window()->IsVisible()) {
     std::string scheme = web_contents()->GetURL().scheme();
@@ -885,7 +899,8 @@ void WebContents::DevToolsFocused() {
 }
 
 void WebContents::DevToolsOpened() {
-  v8::Locker locker(isolate());
+  if (!::tizen::is_single_process)
+    v8::Locker locker(isolate());
   v8::HandleScope handle_scope(isolate());
   auto handle = WebContents::CreateFrom(
       isolate(), managed_web_contents()->GetDevToolsWebContents());
@@ -905,7 +920,8 @@ void WebContents::DevToolsOpened() {
 }
 
 void WebContents::DevToolsClosed() {
-  v8::Locker locker(isolate());
+  if (!::tizen::is_single_process)
+    v8::Locker locker(isolate());
   v8::HandleScope handle_scope(isolate());
   devtools_web_contents_.Reset();
 
@@ -954,6 +970,7 @@ void WebContents::HandleWrtPluginMessage(Ewk_Wrt_Message_Data* msg) {
 bool WebContents::OnMessageReceived(const IPC::Message& message) {
   bool handled = true;
   IPC_BEGIN_MESSAGE_MAP(WebContents, message)
+    IPC_MESSAGE_HANDLER_DELAY_REPLY(WrtViewMsg_GetCSP, OnGetContentSecurityPolicy)
     IPC_MESSAGE_HANDLER(AtomViewHostMsg_Message, OnRendererMessage)
     IPC_MESSAGE_HANDLER_DELAY_REPLY(AtomViewHostMsg_Message_Sync,
                                     OnRendererMessageSync)
@@ -1034,6 +1051,10 @@ void WebContents::LoadURL(const GURL& url, const mate::Dictionary& options) {
     return;
   }
 
+  if (!atom::Browser::Get()->ShouldAllowNavigation(url.spec())) {
+    return;
+  }
+
   content::NavigationController::LoadURLParams params(url);
 
   GURL http_referrer;
@@ -1701,6 +1722,14 @@ void WebContents::OnGetZoomLevel(IPC::Message* reply_msg) {
   Send(reply_msg);
 }
 
+void WebContents::OnGetContentSecurityPolicy(IPC::Message* reply_msg) {
+  std::string csp_rule;
+  std::string csp_report_rule;
+  atom::Browser::Get()->GetCSP(csp_rule, csp_report_rule);
+  WrtViewMsg_GetCSP::WriteReplyParams(reply_msg, csp_rule, csp_report_rule);
+  Send(reply_msg);
+}
+
 v8::Local<v8::Value> WebContents::GetWebPreferences(v8::Isolate* isolate) {
   WebContentsPreferences* web_preferences =
       WebContentsPreferences::FromWebContents(web_contents());