Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Side by Side Diff: chrome/browser/android/bottombar/overlay_panel_content.cc

Issue 1326643003: Overlay content is its own class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move-panel-functionality
Patch Set: address comments Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/bottombar/contextualsearch/contextual_search_pa nel.h" 5 #include "chrome/browser/android/bottombar/overlay_panel_content.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/android/jni_string.h" 9 #include "base/android/jni_string.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "chrome/browser/android/contextualsearch/contextual_search_delegate.h"
14 #include "chrome/browser/android/tab_android.h" 13 #include "chrome/browser/android/tab_android.h"
15 #include "chrome/browser/history/history_service_factory.h" 14 #include "chrome/browser/history/history_service_factory.h"
16 #include "chrome/browser/profiles/profile_manager.h" 15 #include "chrome/browser/profiles/profile_manager.h"
17 #include "chrome/browser/search_engines/template_url_service_factory.h" 16 #include "chrome/browser/search_engines/template_url_service_factory.h"
18 #include "chrome/browser/ui/android/window_android_helper.h" 17 #include "chrome/browser/ui/android/window_android_helper.h"
19 #include "components/history/core/browser/history_service.h" 18 #include "components/history/core/browser/history_service.h"
20 #include "components/navigation_interception/intercept_navigation_delegate.h" 19 #include "components/navigation_interception/intercept_navigation_delegate.h"
21 #include "components/variations/variations_associated_data.h" 20 #include "components/variations/variations_associated_data.h"
22 #include "components/web_contents_delegate_android/web_contents_delegate_android .h" 21 #include "components/web_contents_delegate_android/web_contents_delegate_android .h"
23 #include "content/public/browser/android/content_view_core.h" 22 #include "content/public/browser/android/content_view_core.h"
24 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
25 #include "jni/ContextualSearchPanel_jni.h" 24 #include "jni/OverlayPanelContent_jni.h"
26 #include "net/url_request/url_fetcher_impl.h" 25 #include "net/url_request/url_fetcher_impl.h"
27 26
28 using content::ContentViewCore; 27 using content::ContentViewCore;
29 28
30 namespace { 29 namespace {
31 30
32 const int kHistoryDeletionWindowSeconds = 2; 31 const int kHistoryDeletionWindowSeconds = 2;
33 32
34 // Because we need a callback, this needs to exist. 33 // Because we need a callback, this needs to exist.
35 void OnHistoryDeletionDone() { 34 void OnHistoryDeletionDone() {
36 } 35 }
37 36
38 } // namespace 37 } // namespace
39 38
40 // This class manages the native behavior of the Contextual Search feature. 39 // This class manages the native behavior of the panel.
41 // Instances of this class are owned by the Java ContextualSearchPanel. 40 // Instances of this class are owned by the Java OverlayPanelContentl.
42 ContextualSearchPanel::ContextualSearchPanel(JNIEnv* env, jobject obj) { 41 OverlayPanelContent::OverlayPanelContent(JNIEnv* env, jobject obj) {
43 java_manager_.Reset(env, obj); 42 java_manager_.Reset(env, obj);
44 Java_ContextualSearchPanel_setNativePanelContentPtr( 43 Java_OverlayPanelContent_setNativePanelContentPtr(
45 env, obj, reinterpret_cast<intptr_t>(this)); 44 env, obj, reinterpret_cast<intptr_t>(this));
46 } 45 }
47 46
48 ContextualSearchPanel::~ContextualSearchPanel() { 47 OverlayPanelContent::~OverlayPanelContent() {
49 JNIEnv* env = base::android::AttachCurrentThread(); 48 JNIEnv* env = base::android::AttachCurrentThread();
50 Java_ContextualSearchPanel_clearNativePanelContentPtr( 49 Java_OverlayPanelContent_clearNativePanelContentPtr(
51 env, java_manager_.obj()); 50 env, java_manager_.obj());
52 } 51 }
53 52
54 void ContextualSearchPanel::Destroy(JNIEnv* env, jobject obj) { delete this; } 53 void OverlayPanelContent::Destroy(JNIEnv* env, jobject obj) { delete this; }
55 54
56 void ContextualSearchPanel::RemoveLastHistoryEntry( 55 void OverlayPanelContent::RemoveLastHistoryEntry(
57 JNIEnv* env, 56 JNIEnv* env,
58 jobject obj, 57 jobject obj,
59 jstring search_url, 58 jstring search_url,
60 jlong search_start_time_ms) { 59 jlong search_start_time_ms) {
61 // The deletion window is from the time a search URL was put in history, up 60 // The deletion window is from the time a search URL was put in history, up
62 // to a short amount of time later. 61 // to a short amount of time later.
63 base::Time begin_time = base::Time::FromJsTime(search_start_time_ms); 62 base::Time begin_time = base::Time::FromJsTime(search_start_time_ms);
64 base::Time end_time = begin_time + 63 base::Time end_time = begin_time +
65 base::TimeDelta::FromSeconds(kHistoryDeletionWindowSeconds); 64 base::TimeDelta::FromSeconds(kHistoryDeletionWindowSeconds);
66 65
67 history::HistoryService* service = HistoryServiceFactory::GetForProfile( 66 history::HistoryService* service = HistoryServiceFactory::GetForProfile(
68 ProfileManager::GetActiveUserProfile(), 67 ProfileManager::GetActiveUserProfile(),
69 ServiceAccessType::EXPLICIT_ACCESS); 68 ServiceAccessType::EXPLICIT_ACCESS);
70 if (service) { 69 if (service) {
71 // NOTE(mathp): We are only removing |search_url| from the local history 70 // NOTE(mathp): We are only removing |search_url| from the local history
72 // because search results that are not promoted to a Tab do not make it to 71 // because search results that are not promoted to a Tab do not make it to
73 // the web history, only local. 72 // the web history, only local.
74 std::set<GURL> restrict_set; 73 std::set<GURL> restrict_set;
75 restrict_set.insert( 74 restrict_set.insert(
76 GURL(base::android::ConvertJavaStringToUTF8(env, search_url))); 75 GURL(base::android::ConvertJavaStringToUTF8(env, search_url)));
77 service->ExpireHistoryBetween( 76 service->ExpireHistoryBetween(
78 restrict_set, 77 restrict_set,
79 begin_time, 78 begin_time,
80 end_time, 79 end_time,
81 base::Bind(&OnHistoryDeletionDone), 80 base::Bind(&OnHistoryDeletionDone),
82 &history_task_tracker_); 81 &history_task_tracker_);
83 } 82 }
84 } 83 }
85 84
86 void ContextualSearchPanel::SetWebContents(JNIEnv* env, 85 void OverlayPanelContent::SetWebContents(JNIEnv* env,
87 jobject obj, 86 jobject obj,
88 jobject jcontent_view_core, 87 jobject jcontent_view_core,
89 jobject jweb_contents_delegate) { 88 jobject jweb_contents_delegate) {
90 content::ContentViewCore* content_view_core = 89 content::ContentViewCore* content_view_core =
91 content::ContentViewCore::GetNativeContentViewCore(env, 90 content::ContentViewCore::GetNativeContentViewCore(env,
92 jcontent_view_core); 91 jcontent_view_core);
93 DCHECK(content_view_core); 92 DCHECK(content_view_core);
94 DCHECK(content_view_core->GetWebContents()); 93 DCHECK(content_view_core->GetWebContents());
95 94
96 // NOTE(pedrosimonetti): Takes ownership of the WebContents associated 95 // NOTE(pedrosimonetti): Takes ownership of the WebContents associated
97 // with the ContentViewCore. This is to make sure that the WebContens 96 // with the ContentViewCore. This is to make sure that the WebContens
98 // and the Compositor are in the same process. 97 // and the Compositor are in the same process.
99 // TODO(pedrosimonetti): Confirm with dtrainor@ if the comment above 98 // TODO(pedrosimonetti): Confirm with dtrainor@ if the comment above
100 // is accurate. 99 // is accurate.
101 web_contents_.reset(content_view_core->GetWebContents()); 100 web_contents_.reset(content_view_core->GetWebContents());
102 // TODO(pedrosimonetti): confirm if we need this after promoting it 101 // TODO(pedrosimonetti): confirm if we need this after promoting it
103 // to a real tab. 102 // to a real tab.
104 TabAndroid::AttachTabHelpers(web_contents_.get()); 103 TabAndroid::AttachTabHelpers(web_contents_.get());
105 WindowAndroidHelper::FromWebContents(web_contents_.get()) 104 WindowAndroidHelper::FromWebContents(web_contents_.get())
106 ->SetWindowAndroid(content_view_core->GetWindowAndroid()); 105 ->SetWindowAndroid(content_view_core->GetWindowAndroid());
107 web_contents_delegate_.reset( 106 web_contents_delegate_.reset(
108 new web_contents_delegate_android::WebContentsDelegateAndroid( 107 new web_contents_delegate_android::WebContentsDelegateAndroid(
109 env, jweb_contents_delegate)); 108 env, jweb_contents_delegate));
110 web_contents_->SetDelegate(web_contents_delegate_.get()); 109 web_contents_->SetDelegate(web_contents_delegate_.get());
111 } 110 }
112 111
113 void ContextualSearchPanel::DestroyWebContents(JNIEnv* env, jobject jobj) { 112 void OverlayPanelContent::DestroyWebContents(JNIEnv* env, jobject jobj) {
114 DCHECK(web_contents_.get()); 113 DCHECK(web_contents_.get());
115 web_contents_.reset(); 114 web_contents_.reset();
116 // |web_contents_delegate_| may already be NULL at this point. 115 // |web_contents_delegate_| may already be NULL at this point.
117 web_contents_delegate_.reset(); 116 web_contents_delegate_.reset();
118 } 117 }
119 118
120 void ContextualSearchPanel::SetInterceptNavigationDelegate( 119 void OverlayPanelContent::SetInterceptNavigationDelegate(
121 JNIEnv* env, 120 JNIEnv* env,
122 jobject obj, 121 jobject obj,
123 jobject delegate, 122 jobject delegate,
124 jobject jweb_contents) { 123 jobject jweb_contents) {
125 content::WebContents* web_contents = 124 content::WebContents* web_contents =
126 content::WebContents::FromJavaWebContents(jweb_contents); 125 content::WebContents::FromJavaWebContents(jweb_contents);
127 DCHECK(web_contents); 126 DCHECK(web_contents);
128 navigation_interception::InterceptNavigationDelegate::Associate( 127 navigation_interception::InterceptNavigationDelegate::Associate(
129 web_contents, 128 web_contents,
130 make_scoped_ptr(new navigation_interception::InterceptNavigationDelegate( 129 make_scoped_ptr(new navigation_interception::InterceptNavigationDelegate(
131 env, delegate))); 130 env, delegate)));
132 } 131 }
133 132
134 bool RegisterContextualSearchPanel(JNIEnv* env) { 133 bool RegisterOverlayPanelContent(JNIEnv* env) {
135 return RegisterNativesImpl(env); 134 return RegisterNativesImpl(env);
136 } 135 }
137 136
138 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { 137 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) {
139 ContextualSearchPanel* manager = new ContextualSearchPanel(env, obj); 138 OverlayPanelContent* content = new OverlayPanelContent(env, obj);
140 return reinterpret_cast<intptr_t>(manager); 139 return reinterpret_cast<intptr_t>(content);
141 } 140 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698