Chromium Code Reviews| Index: chrome/browser/android/banners/app_banner_data_fetcher_android.cc |
| diff --git a/chrome/browser/android/banners/app_banner_data_fetcher_android.cc b/chrome/browser/android/banners/app_banner_data_fetcher_android.cc |
| index eaba3f14a8bfb05da7108d7d9ff12c542504b59a..8ea0391b82c95a1f4a4387ddc78e41b52ce426c8 100644 |
| --- a/chrome/browser/android/banners/app_banner_data_fetcher_android.cc |
| +++ b/chrome/browser/android/banners/app_banner_data_fetcher_android.cc |
| @@ -4,11 +4,26 @@ |
| #include "chrome/browser/android/banners/app_banner_data_fetcher_android.h" |
| +#include <vector> |
| + |
| +#include "base/strings/string_util.h" |
| #include "chrome/browser/android/banners/app_banner_infobar_delegate_android.h" |
| +#include "chrome/browser/banners/app_banner_debug_log.h" |
| #include "chrome/browser/infobars/infobar_service.h" |
| #include "chrome/browser/ui/android/infobars/app_banner_infobar_android.h" |
| +#include "chrome/common/chrome_constants.h" |
| +#include "chrome/common/render_messages.h" |
| #include "third_party/skia/include/core/SkBitmap.h" |
| +namespace { |
| + |
| +const char kMetaViewportTagName[] = "viewport"; |
| +const char kMetaViewportWidthDevice[] = "width=device-width"; |
| +const char kMetaViewportInitialScaleInt[] = "initial-scale=1"; |
| +const char kMetaViewportInitialScaleFloat[] = "initial-scale=1.0"; |
| + |
| +} // anonymous namespace |
| + |
| namespace banners { |
| AppBannerDataFetcherAndroid::AppBannerDataFetcherAndroid( |
| @@ -37,6 +52,23 @@ bool AppBannerDataFetcherAndroid::ContinueFetching( |
| return FetchIcon(image_url); |
| } |
| +bool AppBannerDataFetcherAndroid::OnMessageReceived( |
| + const IPC::Message& message) { |
| + bool handled = true; |
|
benwells
2015/06/11 01:54:23
should you call the inherited OnMessageReceived?
dominickn (DO NOT USE)
2015/06/11 03:32:12
It's not inherited from AppBannerDataFetcher (diff
|
| + IPC_BEGIN_MESSAGE_MAP(AppBannerDataFetcherAndroid, message) |
| + IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidRetrieveMetaTagContent, |
| + OnDidRetrieveMetaTagContent) |
| + IPC_MESSAGE_UNHANDLED(handled = false) |
| + IPC_END_MESSAGE_MAP() |
| + return handled; |
| +} |
| + |
| +void AppBannerDataFetcherAndroid::HandleWebApp( |
| + content::WebContents* web_contents) { |
| + Send(new ChromeViewMsg_RetrieveMetaTagContent(routing_id(), validated_url_, |
| + kMetaViewportTagName)); |
| +} |
| + |
| std::string AppBannerDataFetcherAndroid::GetAppIdentifier() { |
| return native_app_data_.is_null() |
| ? AppBannerDataFetcher::GetAppIdentifier() : native_app_package_; |
| @@ -70,4 +102,54 @@ void AppBannerDataFetcherAndroid::ShowBanner(const SkBitmap* icon, |
| ->AddInfoBar(make_scoped_ptr(infobar)); |
| } |
| +// Ideally, we should be able to get this information more directly. For now, we |
| +// parse the retrieved meta viewport tag (if any), and look for the necessary |
| +// strings to determine if the page will scale with the viewport. |
| +void AppBannerDataFetcherAndroid::OnDidRetrieveMetaTagContent( |
| + bool success, |
| + const std::string& tag_name, |
| + const std::string& tag_content, |
| + const GURL& expected_url) { |
| + bool is_responsive = false; |
| + if (success && tag_name == kMetaViewportTagName && |
| + validated_url_ == expected_url && |
| + tag_content.size() <= chrome::kMaxMetaTagAttributeLength) { |
| + std::string local_tag_content; |
| + std::vector<std::string> content_tokens; |
| + |
| + // Perform the following steps: |
| + // 1. strip spaces from the viewport content. |
| + // 2. convert the content to lower case. |
| + // 3. split the viewport content by commas. |
| + // 4. search for the required strings. |
| + base::RemoveChars(tag_content, " ", &local_tag_content); |
| + base::StringToLowerASCII(&local_tag_content); |
| + Tokenize(local_tag_content, ",", &content_tokens); |
| + |
| + for (auto property : content_tokens) { |
|
benwells
2015/06/11 01:54:24
nit: const auto&
|
| + if (property == kMetaViewportWidthDevice || |
| + property == kMetaViewportInitialScaleInt || |
| + property == kMetaViewportInitialScaleFloat) { |
| + is_responsive = true; |
| + break; |
| + } |
| + } |
| + } |
| + |
| + content::WebContents* web_contents = GetWebContents(); |
| + if (is_responsive) { |
|
benwells
2015/06/11 01:54:24
Nit: this would be cleaner as
if (!responsive) {
dominickn (DO NOT USE)
2015/06/11 03:32:12
Done.
|
| + if (!CheckFetcherIsStillAlive(web_contents)) { |
| + OutputDeveloperNotShownMessage(web_contents, |
| + kUserNavigatedBeforeBannerShown); |
| + Cancel(); |
| + return; |
| + } |
| + AppBannerDataFetcher::HandleWebApp(web_contents); |
| + } else { |
| + OutputDeveloperNotShownMessage(web_contents, kMetaViewportTagError); |
| + Cancel(); |
| + return; |
| + } |
| +} |
| + |
| } // namespace banners |