OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/android/webapk/manifest_upgrade_detector_fetcher.h" | 5 #include "chrome/browser/android/webapk/manifest_upgrade_detector_fetcher.h" |
6 | 6 |
7 #include <jni.h> | 7 #include <jni.h> |
8 | 8 |
9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
10 #include "chrome/browser/android/shortcut_helper.h" | |
10 #include "chrome/browser/android/shortcut_info.h" | 11 #include "chrome/browser/android/shortcut_info.h" |
12 #include "chrome/browser/manifest/manifest_icon_selector.h" | |
11 #include "content/public/browser/render_frame_host.h" | 13 #include "content/public/browser/render_frame_host.h" |
12 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
13 #include "content/public/common/manifest.h" | 15 #include "content/public/common/manifest.h" |
14 #include "jni/ManifestUpgradeDetectorFetcher_jni.h" | 16 #include "jni/ManifestUpgradeDetectorFetcher_jni.h" |
15 #include "url/gurl.h" | 17 #include "url/gurl.h" |
16 | 18 |
17 using base::android::JavaParamRef; | 19 using base::android::JavaParamRef; |
18 using base::android::ScopedJavaLocalRef; | 20 using base::android::ScopedJavaLocalRef; |
19 | 21 |
20 namespace { | 22 namespace { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 } | 83 } |
82 | 84 |
83 void ManifestUpgradeDetectorFetcher::DidFinishLoad( | 85 void ManifestUpgradeDetectorFetcher::DidFinishLoad( |
84 content::RenderFrameHost* render_frame_host, | 86 content::RenderFrameHost* render_frame_host, |
85 const GURL& validated_url) { | 87 const GURL& validated_url) { |
86 if (render_frame_host->GetParent()) | 88 if (render_frame_host->GetParent()) |
87 return; | 89 return; |
88 if (!IsInScope(validated_url, scope_)) | 90 if (!IsInScope(validated_url, scope_)) |
89 return; | 91 return; |
90 | 92 |
91 web_contents()->GetManifest( | 93 web_contents()->GetManifest( |
dominickn
2016/08/15 05:27:35
Now that InstallableManager has landed, it would b
pkotwicz
2016/08/15 20:15:03
I have changed manifest_upgrade_detector_fetcher.c
| |
92 base::Bind(&ManifestUpgradeDetectorFetcher::OnDidGetManifest, | 94 base::Bind(&ManifestUpgradeDetectorFetcher::OnDidGetManifest, |
93 weak_ptr_factory_.GetWeakPtr())); | 95 weak_ptr_factory_.GetWeakPtr())); |
94 } | 96 } |
95 | 97 |
96 void ManifestUpgradeDetectorFetcher::OnDidGetManifest( | 98 void ManifestUpgradeDetectorFetcher::OnDidGetManifest( |
97 const GURL& manifest_url, | 99 const GURL& manifest_url, |
98 const content::Manifest& manifest) { | 100 const content::Manifest& manifest) { |
99 // If the manifest is empty, it means the current WebContents doesn't | 101 // If the manifest is empty, it means the current WebContents doesn't |
100 // associate with a Web Manifest. In such case, we ignore the empty manifest | 102 // associate with a Web Manifest. In such case, we ignore the empty manifest |
101 // and continue observing the WebContents's loading until we find a page that | 103 // and continue observing the WebContents's loading until we find a page that |
102 // links to the Web Manifest that we are looking for. | 104 // links to the Web Manifest that we are looking for. |
103 // If the manifest URL is different from the current one, we will continue | 105 // If the manifest URL is different from the current one, we will continue |
104 // observing too. It is based on our assumption that it is invalid for | 106 // observing too. It is based on our assumption that it is invalid for |
105 // web developers to change the Web Manifest location. When it does | 107 // web developers to change the Web Manifest location. When it does |
106 // change, we will treat the new Web Manifest as the one of another WebAPK. | 108 // change, we will treat the new Web Manifest as the one of another WebAPK. |
107 if (manifest.IsEmpty() || web_manifest_url_ != manifest_url) | 109 if (manifest.IsEmpty() || web_manifest_url_ != manifest_url) |
108 return; | 110 return; |
109 | 111 |
110 ShortcutInfo info(GURL::EmptyGURL()); | 112 ShortcutInfo info(GURL::EmptyGURL()); |
111 info.UpdateFromManifest(manifest); | 113 info.UpdateFromManifest(manifest); |
112 info.manifest_url = manifest_url; | 114 info.manifest_url = manifest_url; |
113 | 115 |
116 int ideal_homescreen_icon_size_in_dp = | |
117 ShortcutHelper::GetIdealHomescreenIconSizeInDp(); | |
118 int minimum_homescreen_icon_size_in_dp = | |
119 ShortcutHelper::GetMinimumHomescreenIconSizeInDp(); | |
120 info.icon_url = ManifestIconSelector::FindBestMatchingIcon( | |
121 manifest.icons, ideal_homescreen_icon_size_in_dp, | |
122 minimum_homescreen_icon_size_in_dp); | |
123 | |
114 OnDataAvailable(info); | 124 OnDataAvailable(info); |
115 } | 125 } |
116 | 126 |
117 void ManifestUpgradeDetectorFetcher::OnDataAvailable(const ShortcutInfo& info) { | 127 void ManifestUpgradeDetectorFetcher::OnDataAvailable(const ShortcutInfo& info) { |
118 JNIEnv* env = base::android::AttachCurrentThread(); | 128 JNIEnv* env = base::android::AttachCurrentThread(); |
119 | 129 |
120 ScopedJavaLocalRef<jstring> java_url = | 130 ScopedJavaLocalRef<jstring> java_url = |
121 base::android::ConvertUTF8ToJavaString(env, info.url.spec()); | 131 base::android::ConvertUTF8ToJavaString(env, info.url.spec()); |
122 ScopedJavaLocalRef<jstring> java_scope = | 132 ScopedJavaLocalRef<jstring> java_scope = |
123 base::android::ConvertUTF8ToJavaString(env, info.scope.spec()); | 133 base::android::ConvertUTF8ToJavaString(env, info.scope.spec()); |
124 ScopedJavaLocalRef<jstring> java_name = | 134 ScopedJavaLocalRef<jstring> java_name = |
125 base::android::ConvertUTF16ToJavaString(env, info.name); | 135 base::android::ConvertUTF16ToJavaString(env, info.name); |
126 ScopedJavaLocalRef<jstring> java_short_name = | 136 ScopedJavaLocalRef<jstring> java_short_name = |
127 base::android::ConvertUTF16ToJavaString(env, info.short_name); | 137 base::android::ConvertUTF16ToJavaString(env, info.short_name); |
138 ScopedJavaLocalRef<jstring> java_icon_url = | |
139 base::android::ConvertUTF8ToJavaString(env, info.icon_url.spec()); | |
128 | 140 |
129 Java_ManifestUpgradeDetectorFetcher_onDataAvailable( | 141 Java_ManifestUpgradeDetectorFetcher_onDataAvailable( |
130 env, java_ref_.obj(), | 142 env, java_ref_.obj(), |
131 java_url.obj(), | 143 java_url.obj(), |
132 java_scope.obj(), | 144 java_scope.obj(), |
133 java_name.obj(), | 145 java_name.obj(), |
134 java_short_name.obj(), | 146 java_short_name.obj(), |
147 java_icon_url.obj(), | |
135 info.display, | 148 info.display, |
136 info.orientation, | 149 info.orientation, |
137 info.theme_color, | 150 info.theme_color, |
138 info.background_color); | 151 info.background_color); |
139 } | 152 } |
OLD | NEW |