OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef CHROME_BROWSER_ANDROID_SHORTCUT_HELPER_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_SHORTCUT_HELPER_H_ |
6 #define CHROME_BROWSER_ANDROID_SHORTCUT_HELPER_H_ | 6 #define CHROME_BROWSER_ANDROID_SHORTCUT_HELPER_H_ |
7 | 7 |
8 #include "base/android/jni_helper.h" | 8 #include "base/android/jni_helper.h" |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 // Adds a shortcut to the current URL to the Android home screen. | 29 // Adds a shortcut to the current URL to the Android home screen. |
30 // This proceeds over three phases: | 30 // This proceeds over three phases: |
31 // 1) The renderer is asked to parse out webapp related meta tags with an async | 31 // 1) The renderer is asked to parse out webapp related meta tags with an async |
32 // IPC message. | 32 // IPC message. |
33 // 2) The highest-resolution favicon available is retrieved for use as the | 33 // 2) The highest-resolution favicon available is retrieved for use as the |
34 // icon on the home screen. | 34 // icon on the home screen. |
35 // 3) A JNI call is made to fire an Intent at the Android launcher, which adds | 35 // 3) A JNI call is made to fire an Intent at the Android launcher, which adds |
36 // the shortcut. | 36 // the shortcut. |
37 class ShortcutBuilder : public content::WebContentsObserver { | 37 class ShortcutBuilder : public content::WebContentsObserver { |
38 public: | 38 public: |
39 explicit ShortcutBuilder(content::WebContents* web_contents); | 39 explicit ShortcutBuilder(content::WebContents* web_contents, string16 title); |
40 virtual ~ShortcutBuilder() {} | 40 virtual ~ShortcutBuilder() {} |
41 | 41 |
42 void OnDidRetrieveWebappInformation(bool success, | 42 void OnDidRetrieveWebappInformation(bool success, |
43 bool is_webapp_capable, | 43 bool is_webapp_capable, |
44 const GURL& expected_url); | 44 const GURL& expected_url); |
45 | 45 |
46 void FinishAddingShortcut(const chrome::FaviconBitmapResult& bitmap_result); | 46 void FinishAddingShortcut(const chrome::FaviconBitmapResult& bitmap_result); |
47 | 47 |
48 // WebContentsObserver | 48 // WebContentsObserver |
49 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 49 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
50 virtual void WebContentsDestroyed(content::WebContents* web_contents) | 50 virtual void WebContentsDestroyed(content::WebContents* web_contents) |
51 OVERRIDE; | 51 OVERRIDE; |
52 | 52 |
53 private: | 53 private: |
54 void Destroy(); | 54 void Destroy(); |
55 | 55 |
56 GURL url_; | 56 GURL url_; |
57 string16 title_; | 57 string16 title_; |
58 bool is_webapp_capable_; | 58 bool is_webapp_capable_; |
59 CancelableTaskTracker cancelable_task_tracker_; | 59 CancelableTaskTracker cancelable_task_tracker_; |
60 | 60 |
61 DISALLOW_COPY_AND_ASSIGN(ShortcutBuilder); | 61 DISALLOW_COPY_AND_ASSIGN(ShortcutBuilder); |
62 }; | 62 }; |
63 | 63 |
64 class ShortcutHelper { | 64 class ShortcutHelper { |
65 public: | 65 public: |
66 // Adds a shortcut to the current URL to the Android home screen, firing | 66 // Adds a shortcut to the current URL to the Android home screen, firing |
67 // background tasks to pull all the data required. | 67 // background tasks to pull all the data required. |
68 static void AddShortcut(content::WebContents* web_contents); | 68 static void AddShortcut(content::WebContents* web_contents, string16 title); |
69 | 69 |
70 // Adds a shortcut to the launcher. Must be called from a WorkerPool task. | 70 // Adds a shortcut to the launcher. Must be called from a WorkerPool task. |
71 static void AddShortcutInBackground( | 71 static void AddShortcutInBackground( |
72 const GURL& url, | 72 const GURL& url, |
73 const base::string16& title, | 73 const base::string16& title, |
74 bool is_webapp_capable, | 74 bool is_webapp_capable, |
75 const chrome::FaviconBitmapResult& bitmap_result); | 75 const chrome::FaviconBitmapResult& bitmap_result); |
76 | 76 |
77 // Registers JNI hooks. | 77 // Registers JNI hooks. |
78 static bool RegisterShortcutHelper(JNIEnv* env); | 78 static bool RegisterShortcutHelper(JNIEnv* env); |
79 | 79 |
80 private: | 80 private: |
81 DISALLOW_COPY_AND_ASSIGN(ShortcutHelper); | 81 DISALLOW_COPY_AND_ASSIGN(ShortcutHelper); |
82 }; | 82 }; |
83 | 83 |
84 #endif // CHROME_BROWSER_ANDROID_SHORTCUT_HELPER_H_ | 84 #endif // CHROME_BROWSER_ANDROID_SHORTCUT_HELPER_H_ |
OLD | NEW |