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

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: flip booleans for testing renamed api Created 5 years, 2 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(
45 env, obj, reinterpret_cast<intptr_t>(this));
46 } 43 }
47 44
48 ContextualSearchPanel::~ContextualSearchPanel() { 45 OverlayPanelContent::~OverlayPanelContent() {
49 JNIEnv* env = base::android::AttachCurrentThread(); 46 JNIEnv* env = base::android::AttachCurrentThread();
50 Java_ContextualSearchPanel_clearNativePanelContentPtr( 47 Java_OverlayPanelContent_clearNativePanelContentPtr(
51 env, java_manager_.obj()); 48 env, java_manager_.obj());
52 } 49 }
53 50
54 void ContextualSearchPanel::Destroy(JNIEnv* env, jobject obj) { delete this; } 51 void OverlayPanelContent::Destroy(JNIEnv* env, jobject obj) { delete this; }
55 52
56 void ContextualSearchPanel::RemoveLastHistoryEntry( 53 void OverlayPanelContent::RemoveLastHistoryEntry(
57 JNIEnv* env, 54 JNIEnv* env,
58 jobject obj, 55 jobject obj,
59 jstring search_url, 56 jstring search_url,
60 jlong search_start_time_ms) { 57 jlong search_start_time_ms) {
61 // The deletion window is from the time a search URL was put in history, up 58 // The deletion window is from the time a search URL was put in history, up
62 // to a short amount of time later. 59 // to a short amount of time later.
63 base::Time begin_time = base::Time::FromJsTime(search_start_time_ms); 60 base::Time begin_time = base::Time::FromJsTime(search_start_time_ms);
64 base::Time end_time = begin_time + 61 base::Time end_time = begin_time +
65 base::TimeDelta::FromSeconds(kHistoryDeletionWindowSeconds); 62 base::TimeDelta::FromSeconds(kHistoryDeletionWindowSeconds);
66 63
67 history::HistoryService* service = HistoryServiceFactory::GetForProfile( 64 history::HistoryService* service = HistoryServiceFactory::GetForProfile(
68 ProfileManager::GetActiveUserProfile(), 65 ProfileManager::GetActiveUserProfile(),
69 ServiceAccessType::EXPLICIT_ACCESS); 66 ServiceAccessType::EXPLICIT_ACCESS);
70 if (service) { 67 if (service) {
71 // NOTE(mathp): We are only removing |search_url| from the local history 68 // 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 69 // because search results that are not promoted to a Tab do not make it to
73 // the web history, only local. 70 // the web history, only local.
74 std::set<GURL> restrict_set; 71 std::set<GURL> restrict_set;
75 restrict_set.insert( 72 restrict_set.insert(
76 GURL(base::android::ConvertJavaStringToUTF8(env, search_url))); 73 GURL(base::android::ConvertJavaStringToUTF8(env, search_url)));
77 service->ExpireHistoryBetween( 74 service->ExpireHistoryBetween(
78 restrict_set, 75 restrict_set,
79 begin_time, 76 begin_time,
80 end_time, 77 end_time,
81 base::Bind(&OnHistoryDeletionDone), 78 base::Bind(&OnHistoryDeletionDone),
82 &history_task_tracker_); 79 &history_task_tracker_);
83 } 80 }
84 } 81 }
85 82
86 void ContextualSearchPanel::SetWebContents(JNIEnv* env, 83 void OverlayPanelContent::SetWebContents(JNIEnv* env,
87 jobject obj, 84 jobject obj,
88 jobject jcontent_view_core, 85 jobject jcontent_view_core,
89 jobject jweb_contents_delegate) { 86 jobject jweb_contents_delegate) {
90 content::ContentViewCore* content_view_core = 87 content::ContentViewCore* content_view_core =
91 content::ContentViewCore::GetNativeContentViewCore(env, 88 content::ContentViewCore::GetNativeContentViewCore(env,
92 jcontent_view_core); 89 jcontent_view_core);
93 DCHECK(content_view_core); 90 DCHECK(content_view_core);
94 DCHECK(content_view_core->GetWebContents()); 91 DCHECK(content_view_core->GetWebContents());
95 92
96 // NOTE(pedrosimonetti): Takes ownership of the WebContents associated 93 // NOTE(pedrosimonetti): Takes ownership of the WebContents associated
97 // with the ContentViewCore. This is to make sure that the WebContens 94 // with the ContentViewCore. This is to make sure that the WebContens
98 // and the Compositor are in the same process. 95 // and the Compositor are in the same process.
99 // TODO(pedrosimonetti): Confirm with dtrainor@ if the comment above 96 // TODO(pedrosimonetti): Confirm with dtrainor@ if the comment above
100 // is accurate. 97 // is accurate.
101 web_contents_.reset(content_view_core->GetWebContents()); 98 web_contents_.reset(content_view_core->GetWebContents());
102 // TODO(pedrosimonetti): confirm if we need this after promoting it 99 // TODO(pedrosimonetti): confirm if we need this after promoting it
103 // to a real tab. 100 // to a real tab.
104 TabAndroid::AttachTabHelpers(web_contents_.get()); 101 TabAndroid::AttachTabHelpers(web_contents_.get());
105 WindowAndroidHelper::FromWebContents(web_contents_.get()) 102 WindowAndroidHelper::FromWebContents(web_contents_.get())
106 ->SetWindowAndroid(content_view_core->GetWindowAndroid()); 103 ->SetWindowAndroid(content_view_core->GetWindowAndroid());
107 web_contents_delegate_.reset( 104 web_contents_delegate_.reset(
108 new web_contents_delegate_android::WebContentsDelegateAndroid( 105 new web_contents_delegate_android::WebContentsDelegateAndroid(
109 env, jweb_contents_delegate)); 106 env, jweb_contents_delegate));
110 web_contents_->SetDelegate(web_contents_delegate_.get()); 107 web_contents_->SetDelegate(web_contents_delegate_.get());
111 } 108 }
112 109
113 void ContextualSearchPanel::DestroyWebContents(JNIEnv* env, jobject jobj) { 110 void OverlayPanelContent::DestroyWebContents(JNIEnv* env, jobject jobj) {
114 DCHECK(web_contents_.get()); 111 DCHECK(web_contents_.get());
115 web_contents_.reset(); 112 web_contents_.reset();
116 // |web_contents_delegate_| may already be NULL at this point. 113 // |web_contents_delegate_| may already be NULL at this point.
117 web_contents_delegate_.reset(); 114 web_contents_delegate_.reset();
118 } 115 }
119 116
120 void ContextualSearchPanel::SetInterceptNavigationDelegate( 117 void OverlayPanelContent::SetInterceptNavigationDelegate(
121 JNIEnv* env, 118 JNIEnv* env,
122 jobject obj, 119 jobject obj,
123 jobject delegate, 120 jobject delegate,
124 jobject jweb_contents) { 121 jobject jweb_contents) {
125 content::WebContents* web_contents = 122 content::WebContents* web_contents =
126 content::WebContents::FromJavaWebContents(jweb_contents); 123 content::WebContents::FromJavaWebContents(jweb_contents);
127 DCHECK(web_contents); 124 DCHECK(web_contents);
128 navigation_interception::InterceptNavigationDelegate::Associate( 125 navigation_interception::InterceptNavigationDelegate::Associate(
129 web_contents, 126 web_contents,
130 make_scoped_ptr(new navigation_interception::InterceptNavigationDelegate( 127 make_scoped_ptr(new navigation_interception::InterceptNavigationDelegate(
131 env, delegate))); 128 env, delegate)));
132 } 129 }
133 130
134 bool RegisterContextualSearchPanel(JNIEnv* env) { 131 bool RegisterOverlayPanelContent(JNIEnv* env) {
135 return RegisterNativesImpl(env); 132 return RegisterNativesImpl(env);
136 } 133 }
137 134
138 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { 135 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) {
139 ContextualSearchPanel* manager = new ContextualSearchPanel(env, obj); 136 OverlayPanelContent* content = new OverlayPanelContent(env, obj);
140 return reinterpret_cast<intptr_t>(manager); 137 return reinterpret_cast<intptr_t>(content);
141 } 138 }
OLDNEW
« no previous file with comments | « chrome/browser/android/bottombar/overlay_panel_content.h ('k') | chrome/browser/android/chrome_jni_registrar.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698