Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / search / local_ntp_source.cc
index 6e668d7..f6f649c 100644 (file)
 #include "chrome/common/url_constants.h"
 #include "grit/browser_resources.h"
 #include "grit/generated_resources.h"
+#include "grit/theme_resources.h"
 #include "grit/ui_resources.h"
 #include "net/url_request/url_request.h"
 #include "ui/base/l10n/l10n_util.h"
 #include "ui/base/resource/resource_bundle.h"
 #include "ui/base/webui/jstemplate_builder.h"
+#include "ui/base/webui/web_ui_util.h"
 #include "url/gurl.h"
 
 namespace {
@@ -46,10 +48,9 @@ const struct Resource{
   { "images/close_2_hover.png", IDR_CLOSE_2_H, "image/png" },
   { "images/close_2_active.png", IDR_CLOSE_2_P, "image/png" },
   { "images/close_2_white.png", IDR_CLOSE_2_MASK, "image/png" },
-  { "images/2x/google_logo.png",
-    IDR_LOCAL_NTP_IMAGES_2X_LOGO_PNG, "image/png" },
-  { "images/2x/white_google_logo.png",
-    IDR_LOCAL_NTP_IMAGES_2X_WHITE_LOGO_PNG, "image/png" },
+  { "images/google_logo.png", IDR_LOCAL_NTP_IMAGES_LOGO_PNG, "image/png" },
+  { "images/white_google_logo.png",
+    IDR_LOCAL_NTP_IMAGES_WHITE_LOGO_PNG, "image/png" },
 };
 
 // Strips any query parameters from the specified path.
@@ -105,7 +106,8 @@ std::string GetConfigData(Profile* profile) {
   base::DictionaryValue config_data;
   config_data.Set("translatedStrings", GetTranslatedStrings().release());
   config_data.SetBoolean("isGooglePage",
-                         DefaultSearchProviderIsGoogle(profile));
+                         DefaultSearchProviderIsGoogle(profile) &&
+                         chrome::ShouldShowGoogleLocalNTP());
 
   // Serialize the dictionary.
   std::string js_text;
@@ -119,6 +121,11 @@ std::string GetConfigData(Profile* profile) {
   return config_data_js;
 }
 
+std::string GetLocalNtpPath() {
+  return std::string(chrome::kChromeSearchScheme) + "://" +
+         std::string(chrome::kChromeSearchLocalNtpHost) + "/";
+}
+
 }  // namespace
 
 LocalNtpSource::LocalNtpSource(Profile* profile) : profile_(profile) {
@@ -142,11 +149,15 @@ void LocalNtpSource::StartDataRequest(
     callback.Run(base::RefCountedString::TakeString(&config_data_js));
     return;
   }
+  ui::ScaleFactor scale_factor;
+  std::string filename;
+  webui::ParsePathAndScale(
+      GURL(GetLocalNtpPath() + stripped_path), &filename, &scale_factor);
   for (size_t i = 0; i < arraysize(kResources); ++i) {
-    if (stripped_path == kResources[i].filename) {
+    if (filename == kResources[i].filename) {
       scoped_refptr<base::RefCountedStaticMemory> response(
-          ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
-              kResources[i].identifier));
+          ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale(
+              kResources[i].identifier, scale_factor));
       callback.Run(response.get());
       return;
     }
@@ -171,8 +182,8 @@ bool LocalNtpSource::ShouldServiceRequest(
     return false;
 
   if (request->url().SchemeIs(chrome::kChromeSearchScheme)) {
-    DCHECK(StartsWithASCII(request->url().path(), "/", true));
-    std::string filename = request->url().path().substr(1);
+    std::string filename;
+    webui::ParsePathAndScale(request->url(), &filename, NULL);
     for (size_t i = 0; i < arraysize(kResources); ++i) {
       if (filename == kResources[i].filename)
         return true;