| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_UI_TAB_CONTENTS_CORE_TAB_HELPER_H_ | 5 #ifndef CHROME_BROWSER_UI_TAB_CONTENTS_CORE_TAB_HELPER_H_ |
| 6 #define CHROME_BROWSER_UI_TAB_CONTENTS_CORE_TAB_HELPER_H_ | 6 #define CHROME_BROWSER_UI_TAB_CONTENTS_CORE_TAB_HELPER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/id_map.h" | |
| 12 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "chrome/common/thumbnail_capturer.mojom.h" |
| 14 #include "content/public/browser/web_contents_observer.h" | 15 #include "content/public/browser/web_contents_observer.h" |
| 15 #include "content/public/browser/web_contents_user_data.h" | 16 #include "content/public/browser/web_contents_user_data.h" |
| 16 #include "ui/gfx/geometry/size.h" | 17 #include "ui/gfx/geometry/size.h" |
| 17 #include "url/gurl.h" | 18 #include "url/gurl.h" |
| 18 | 19 |
| 19 class CoreTabHelperDelegate; | 20 class CoreTabHelperDelegate; |
| 20 | 21 |
| 21 // Per-tab class to handle functionality that is core to the operation of tabs. | 22 // Per-tab class to handle functionality that is core to the operation of tabs. |
| 22 class CoreTabHelper : public content::WebContentsObserver, | 23 class CoreTabHelper : public content::WebContentsObserver, |
| 23 public content::WebContentsUserData<CoreTabHelper> { | 24 public content::WebContentsUserData<CoreTabHelper> { |
| 24 public: | 25 public: |
| 25 using ContextNodeThumbnailCallback = | |
| 26 base::Callback<void(const std::string&, const gfx::Size&)>; | |
| 27 | |
| 28 ~CoreTabHelper() override; | 26 ~CoreTabHelper() override; |
| 29 | 27 |
| 30 // Initial title assigned to NavigationEntries from Navigate. | 28 // Initial title assigned to NavigationEntries from Navigate. |
| 31 static base::string16 GetDefaultTitle(); | 29 static base::string16 GetDefaultTitle(); |
| 32 | 30 |
| 33 // Returns a human-readable description the tab's loading state. | 31 // Returns a human-readable description the tab's loading state. |
| 34 base::string16 GetStatusText() const; | 32 base::string16 GetStatusText() const; |
| 35 | 33 |
| 36 // Notification that tab closing has started. This can be called multiple | 34 // Notification that tab closing has started. This can be called multiple |
| 37 // times, subsequent calls are ignored. | 35 // times, subsequent calls are ignored. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 49 // Set the time during close when the tab is no longer visible. | 47 // Set the time during close when the tab is no longer visible. |
| 50 void OnUnloadDetachedStarted(); | 48 void OnUnloadDetachedStarted(); |
| 51 | 49 |
| 52 void UpdateContentRestrictions(int content_restrictions); | 50 void UpdateContentRestrictions(int content_restrictions); |
| 53 | 51 |
| 54 // Perform an image search for the image that triggered the context menu. The | 52 // Perform an image search for the image that triggered the context menu. The |
| 55 // |src_url| is passed to the search request and is not used directly to fetch | 53 // |src_url| is passed to the search request and is not used directly to fetch |
| 56 // the image resources. | 54 // the image resources. |
| 57 void SearchByImageInNewTab(content::RenderFrameHost* render_frame_host, | 55 void SearchByImageInNewTab(content::RenderFrameHost* render_frame_host, |
| 58 const GURL& src_url); | 56 const GURL& src_url); |
| 59 void RequestThumbnailForContextNode( | |
| 60 content::RenderFrameHost* render_frame_host, | |
| 61 int minimum_size, | |
| 62 gfx::Size maximum_size, | |
| 63 const ContextNodeThumbnailCallback& callback); | |
| 64 | 57 |
| 65 CoreTabHelperDelegate* delegate() const { return delegate_; } | 58 CoreTabHelperDelegate* delegate() const { return delegate_; } |
| 66 void set_delegate(CoreTabHelperDelegate* d) { delegate_ = d; } | 59 void set_delegate(CoreTabHelperDelegate* d) { delegate_ = d; } |
| 67 | 60 |
| 68 void set_new_tab_start_time(const base::TimeTicks& time) { | 61 void set_new_tab_start_time(const base::TimeTicks& time) { |
| 69 new_tab_start_time_ = time; | 62 new_tab_start_time_ = time; |
| 70 } | 63 } |
| 71 | 64 |
| 72 base::TimeTicks new_tab_start_time() const { return new_tab_start_time_; } | 65 base::TimeTicks new_tab_start_time() const { return new_tab_start_time_; } |
| 73 int content_restrictions() const { return content_restrictions_; } | 66 int content_restrictions() const { return content_restrictions_; } |
| 74 | 67 |
| 75 private: | 68 private: |
| 76 explicit CoreTabHelper(content::WebContents* web_contents); | 69 explicit CoreTabHelper(content::WebContents* web_contents); |
| 77 friend class content::WebContentsUserData<CoreTabHelper>; | 70 friend class content::WebContentsUserData<CoreTabHelper>; |
| 78 | 71 |
| 79 static bool GetStatusTextForWebContents(base::string16* status_text, | 72 static bool GetStatusTextForWebContents(base::string16* status_text, |
| 80 content::WebContents* source); | 73 content::WebContents* source); |
| 81 | 74 |
| 82 // content::WebContentsObserver overrides: | 75 // content::WebContentsObserver overrides: |
| 83 void DidStartLoading() override; | 76 void DidStartLoading() override; |
| 84 void WasShown() override; | 77 void WasShown() override; |
| 85 void WebContentsDestroyed() override; | 78 void WebContentsDestroyed() override; |
| 86 void BeforeUnloadFired(const base::TimeTicks& proceed_time) override; | 79 void BeforeUnloadFired(const base::TimeTicks& proceed_time) override; |
| 87 void BeforeUnloadDialogCancelled() override; | 80 void BeforeUnloadDialogCancelled() override; |
| 88 bool OnMessageReceived(const IPC::Message& message, | |
| 89 content::RenderFrameHost* render_frame_host) override; | |
| 90 | 81 |
| 91 void OnRequestThumbnailForContextNodeACK(const std::string& thumbnail_data, | 82 void DoSearchByImageInNewTab( |
| 92 const gfx::Size& original_size, | 83 chrome::mojom::ThumbnailCapturerPtr thumbnail_capturer, |
| 93 int callback_id); | 84 const GURL& src_url, |
| 94 void DoSearchByImageInNewTab(const GURL& src_url, | 85 const std::vector<uint8_t>& thumbnail_data, |
| 95 const std::string& thumbnail_data, | 86 const gfx::Size& original_size); |
| 96 const gfx::Size& original_size); | |
| 97 | 87 |
| 98 // Delegate for notifying our owner about stuff. Not owned by us. | 88 // Delegate for notifying our owner about stuff. Not owned by us. |
| 99 CoreTabHelperDelegate* delegate_; | 89 CoreTabHelperDelegate* delegate_; |
| 100 | 90 |
| 101 // The time when we started to create the new tab page. This time is from | 91 // The time when we started to create the new tab page. This time is from |
| 102 // before we created this WebContents. | 92 // before we created this WebContents. |
| 103 base::TimeTicks new_tab_start_time_; | 93 base::TimeTicks new_tab_start_time_; |
| 104 | 94 |
| 105 // The time that we started to close this WebContents. | 95 // The time that we started to close this WebContents. |
| 106 base::TimeTicks close_start_time_; | 96 base::TimeTicks close_start_time_; |
| 107 | 97 |
| 108 // The time when onbeforeunload ended. | 98 // The time when onbeforeunload ended. |
| 109 base::TimeTicks before_unload_end_time_; | 99 base::TimeTicks before_unload_end_time_; |
| 110 | 100 |
| 111 // The time when the tab was removed from view during close. | 101 // The time when the tab was removed from view during close. |
| 112 base::TimeTicks unload_detached_start_time_; | 102 base::TimeTicks unload_detached_start_time_; |
| 113 | 103 |
| 114 // Content restrictions, used to disable print/copy etc based on content's | 104 // Content restrictions, used to disable print/copy etc based on content's |
| 115 // (full-page plugins for now only) permissions. | 105 // (full-page plugins for now only) permissions. |
| 116 int content_restrictions_; | 106 int content_restrictions_; |
| 117 | 107 |
| 118 IDMap<std::unique_ptr<ContextNodeThumbnailCallback>> thumbnail_callbacks_; | 108 base::WeakPtrFactory<CoreTabHelper> weak_factory_; |
| 119 | 109 |
| 120 DISALLOW_COPY_AND_ASSIGN(CoreTabHelper); | 110 DISALLOW_COPY_AND_ASSIGN(CoreTabHelper); |
| 121 }; | 111 }; |
| 122 | 112 |
| 123 #endif // CHROME_BROWSER_UI_TAB_CONTENTS_CORE_TAB_HELPER_H_ | 113 #endif // CHROME_BROWSER_UI_TAB_CONTENTS_CORE_TAB_HELPER_H_ |
| OLD | NEW |