Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / renderer / chrome_render_view_observer.cc
index bbfe199..38aaae9 100644 (file)
 #include "chrome/common/prerender_messages.h"
 #include "chrome/common/render_messages.h"
 #include "chrome/common/url_constants.h"
-#include "chrome/renderer/chrome_render_process_observer.h"
+#include "chrome/renderer/isolated_world_ids.h"
 #include "chrome/renderer/prerender/prerender_helper.h"
 #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h"
-#include "chrome/renderer/translate/translate_helper.h"
+#include "chrome/renderer/web_apps.h"
 #include "chrome/renderer/webview_color_overlay.h"
+#include "components/translate/content/renderer/translate_helper.h"
+#include "components/web_cache/renderer/web_cache_render_process_observer.h"
 #include "content/public/common/bindings_policy.h"
 #include "content/public/renderer/content_renderer_client.h"
 #include "content/public/renderer/render_frame.h"
 #include "content/public/renderer/render_view.h"
 #include "extensions/common/constants.h"
+#include "extensions/renderer/extension_groups.h"
 #include "net/base/data_url.h"
 #include "skia/ext/platform_canvas.h"
 #include "third_party/WebKit/public/platform/WebCString.h"
@@ -154,10 +157,14 @@ bool RetrieveMetaTagContent(const WebFrame* main_frame,
 
 ChromeRenderViewObserver::ChromeRenderViewObserver(
     content::RenderView* render_view,
-    ChromeRenderProcessObserver* chrome_render_process_observer)
+    web_cache::WebCacheRenderProcessObserver* web_cache_render_process_observer)
     : content::RenderViewObserver(render_view),
-      chrome_render_process_observer_(chrome_render_process_observer),
-      translate_helper_(new TranslateHelper(render_view)),
+      web_cache_render_process_observer_(web_cache_render_process_observer),
+      translate_helper_(new translate::TranslateHelper(
+          render_view,
+          chrome::ISOLATED_WORLD_ID_TRANSLATE,
+          extensions::EXTENSION_GROUP_INTERNAL_TRANSLATE_SCRIPTS,
+          extensions::kExtensionScheme)),
       phishing_classifier_(NULL),
       capture_timer_(false, false) {
   const CommandLine& command_line = *CommandLine::ForCurrentProcess();
@@ -175,18 +182,17 @@ bool ChromeRenderViewObserver::OnMessageReceived(const IPC::Message& message) {
     IPC_MESSAGE_HANDLER(ChromeViewMsg_WebUIJavaScript, OnWebUIJavaScript)
 #endif
 #if defined(ENABLE_EXTENSIONS)
-    IPC_MESSAGE_HANDLER(ChromeViewMsg_SetName, OnSetName)
     IPC_MESSAGE_HANDLER(ChromeViewMsg_SetVisuallyDeemphasized,
                         OnSetVisuallyDeemphasized)
 #endif
 #if defined(OS_ANDROID)
     IPC_MESSAGE_HANDLER(ChromeViewMsg_UpdateTopControlsState,
                         OnUpdateTopControlsState)
-    IPC_MESSAGE_HANDLER(ChromeViewMsg_RetrieveWebappInformation,
-                        OnRetrieveWebappInformation)
     IPC_MESSAGE_HANDLER(ChromeViewMsg_RetrieveMetaTagContent,
                         OnRetrieveMetaTagContent)
 #endif
+    IPC_MESSAGE_HANDLER(ChromeViewMsg_GetWebApplicationInfo,
+                        OnGetWebApplicationInfo)
     IPC_MESSAGE_HANDLER(ChromeViewMsg_SetClientSidePhishingDetection,
                         OnSetClientSidePhishingDetection)
     IPC_MESSAGE_HANDLER(ChromeViewMsg_SetWindowFeatures, OnSetWindowFeatures)
@@ -211,52 +217,6 @@ void ChromeRenderViewObserver::OnUpdateTopControlsState(
   render_view()->UpdateTopControlsState(constraints, current, animate);
 }
 
-void ChromeRenderViewObserver::OnRetrieveWebappInformation(
-    const GURL& expected_url) {
-  WebFrame* main_frame = render_view()->GetWebView()->mainFrame();
-  bool found_tag;
-  std::string content_str;
-
-  // Search for the "mobile-web-app-capable" tag.
-  bool mobile_parse_success = RetrieveMetaTagContent(
-      main_frame,
-      expected_url,
-      "mobile-web-app-capable",
-      &found_tag,
-      &content_str);
-  bool is_mobile_webapp_capable = mobile_parse_success && found_tag &&
-      LowerCaseEqualsASCII(content_str, "yes");
-
-  // Search for the "apple-mobile-web-app-capable" tag.
-  bool apple_parse_success = RetrieveMetaTagContent(
-      main_frame,
-      expected_url,
-      "apple-mobile-web-app-capable",
-      &found_tag,
-      &content_str);
-  bool is_apple_mobile_webapp_capable = apple_parse_success && found_tag &&
-      LowerCaseEqualsASCII(content_str, "yes");
-
-  bool is_only_apple_mobile_webapp_capable =
-      is_apple_mobile_webapp_capable && !is_mobile_webapp_capable;
-  if (main_frame && is_only_apple_mobile_webapp_capable) {
-    blink::WebConsoleMessage message(
-        blink::WebConsoleMessage::LevelWarning,
-        "<meta name=\"apple-mobile-web-app-capable\" content=\"yes\"> is "
-        "deprecated. Please include <meta name=\"mobile-web-app-capable\" "
-        "content=\"yes\"> - "
-        "http://developers.google.com/chrome/mobile/docs/installtohomescreen");
-    main_frame->addMessageToConsole(message);
-  }
-
-  Send(new ChromeViewHostMsg_DidRetrieveWebappInformation(
-      routing_id(),
-      mobile_parse_success && apple_parse_success,
-      is_mobile_webapp_capable,
-      is_apple_mobile_webapp_capable,
-      expected_url));
-}
-
 void ChromeRenderViewObserver::OnRetrieveMetaTagContent(
     const GURL& expected_url,
     const std::string tag_name) {
@@ -278,6 +238,48 @@ void ChromeRenderViewObserver::OnRetrieveMetaTagContent(
 }
 #endif
 
+void ChromeRenderViewObserver::OnGetWebApplicationInfo() {
+  WebFrame* main_frame = render_view()->GetWebView()->mainFrame();
+  DCHECK(main_frame);
+
+  WebApplicationInfo web_app_info;
+  web_apps::ParseWebAppFromWebDocument(main_frame, &web_app_info);
+
+  // The warning below is specific to mobile but it doesn't hurt to show it even
+  // if the Chromium build is running on a desktop. It will get more exposition.
+  if (web_app_info.mobile_capable ==
+        WebApplicationInfo::MOBILE_CAPABLE_APPLE) {
+    blink::WebConsoleMessage message(
+        blink::WebConsoleMessage::LevelWarning,
+        "<meta name=\"apple-mobile-web-app-capable\" content=\"yes\"> is "
+        "deprecated. Please include <meta name=\"mobile-web-app-capable\" "
+        "content=\"yes\"> - "
+        "http://developers.google.com/chrome/mobile/docs/installtohomescreen");
+    main_frame->addMessageToConsole(message);
+  }
+
+  // Prune out any data URLs in the set of icons.  The browser process expects
+  // any icon with a data URL to have originated from a favicon.  We don't want
+  // to decode arbitrary data URLs in the browser process.  See
+  // http://b/issue?id=1162972
+  for (std::vector<WebApplicationInfo::IconInfo>::iterator it =
+          web_app_info.icons.begin(); it != web_app_info.icons.end();) {
+    if (it->url.SchemeIs(url::kDataScheme))
+      it = web_app_info.icons.erase(it);
+    else
+      ++it;
+  }
+
+  // Truncate the strings we send to the browser process.
+  web_app_info.title =
+      web_app_info.title.substr(0, chrome::kMaxMetaTagAttributeLength);
+  web_app_info.description =
+      web_app_info.description.substr(0, chrome::kMaxMetaTagAttributeLength);
+
+  Send(new ChromeViewHostMsg_DidGetWebApplicationInfo(
+      routing_id(), web_app_info));
+}
+
 void ChromeRenderViewObserver::OnSetWindowFeatures(
     const WebWindowFeatures& window_features) {
   render_view()->GetWebView()->setWindowFeatures(window_features);
@@ -286,8 +288,8 @@ void ChromeRenderViewObserver::OnSetWindowFeatures(
 void ChromeRenderViewObserver::Navigate(const GURL& url) {
   // Execute cache clear operations that were postponed until a navigation
   // event (including tab reload).
-  if (chrome_render_process_observer_)
-    chrome_render_process_observer_->ExecutePendingClearCache();
+  if (web_cache_render_process_observer_)
+    web_cache_render_process_observer_->ExecutePendingClearCache();
   // Let translate_helper do any preparatory work for loading a URL.
   if (translate_helper_)
     translate_helper_->PrepareForUrl(url);
@@ -303,12 +305,6 @@ void ChromeRenderViewObserver::OnSetClientSidePhishingDetection(
 }
 
 #if defined(ENABLE_EXTENSIONS)
-void ChromeRenderViewObserver::OnSetName(const std::string& name) {
-  blink::WebView* web_view = render_view()->GetWebView();
-  if (web_view)
-    web_view->mainFrame()->setName(WebString::fromUTF8(name));
-}
-
 void ChromeRenderViewObserver::OnSetVisuallyDeemphasized(bool deemphasized) {
   bool already_deemphasized = !!dimmed_color_overlay_.get();
   if (already_deemphasized == deemphasized)