| 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..1862556ff53cf4609665176547c2e9b8118c4ce6 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;
|
| + 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_;
|
| @@ -66,8 +98,61 @@ void AppBannerDataFetcherAndroid::ShowBanner(const SkBitmap* icon,
|
| if (infobar)
|
| RecordDidShowBanner("AppBanner.NativeApp.Shown");
|
| }
|
| - InfoBarService::FromWebContents(web_contents)
|
| - ->AddInfoBar(make_scoped_ptr(infobar));
|
| + if (infobar) {
|
| + InfoBarService::FromWebContents(web_contents)
|
| + ->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 (const auto& property : content_tokens) {
|
| + if (property == kMetaViewportWidthDevice ||
|
| + property == kMetaViewportInitialScaleInt ||
|
| + property == kMetaViewportInitialScaleFloat) {
|
| + is_responsive = true;
|
| + break;
|
| + }
|
| + }
|
| + }
|
| +
|
| + content::WebContents* web_contents = GetWebContents();
|
| + if (!is_responsive) {
|
| + OutputDeveloperNotShownMessage(web_contents, kMetaViewportTagError);
|
| + Cancel();
|
| + return;
|
| + }
|
| +
|
| + if (!CheckFetcherIsStillAlive(web_contents)) {
|
| + OutputDeveloperNotShownMessage(web_contents,
|
| + kUserNavigatedBeforeBannerShown);
|
| + Cancel();
|
| + return;
|
| + }
|
| +
|
| + AppBannerDataFetcher::HandleWebApp(web_contents);
|
| }
|
|
|
| } // namespace banners
|
|
|