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

Side by Side Diff: chrome/browser/component/navigation_interception/intercept_navigation_delegate.cc

Issue 10946008: Componentize IgnoreNavigationResourceThrottle and add chrome and webview specific implementations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: moved jni to component, added Java test code Created 8 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/component/navigation_interception/intercept_navigation_ delegate.h"
6
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h"
9 #include "base/callback.h"
10 #include "chrome/browser/component/navigation_interception/intercept_navigation_ resource_throttle.h"
11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/render_view_host.h"
13 #include "content/public/browser/web_contents.h"
14 #include "googleurl/src/gurl.h"
15 #include "jni/InterceptNavigationDelegate_jni.h"
16 #include "net/url_request/url_request.h"
17
18 using base::android::ConvertUTF8ToJavaString;
19 using base::android::ScopedJavaLocalRef;
20 using content::BrowserThread;
21 using content::RenderViewHost;
22 using content::WebContents;
23
24 namespace navigation_interception {
25
26 namespace {
27
28 const void* kInterceptNavigationDelegateUserDataKey =
29 &kInterceptNavigationDelegateUserDataKey;
30
31 bool CheckIfShouldIgnoreNavigationOnUIThread(RenderViewHost* source,
32 const GURL& url,
33 const content::Referrer& referrer,
34 bool has_user_gesture) {
35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
36 DCHECK(source);
37
38 WebContents* web_contents = WebContents::FromRenderViewHost(source);
39 if (!web_contents) return false;
joth 2012/10/03 22:01:32 nit: in c++ we put the non-braced statement on its
mkosiba (inactive) 2012/10/08 15:09:12 Done.
40 InterceptNavigationDelegate* intercept_navigation_delegate =
41 InterceptNavigationDelegate::Get(web_contents);
42 if (!intercept_navigation_delegate) return false;
43
44 return intercept_navigation_delegate->ShouldIgnoreNavigation(
45 url, has_user_gesture);
46 }
47
48 } // namespace
49
50 // static
51 void InterceptNavigationDelegate::Associate(
joth 2012/10/03 22:01:32 note in header that it transfers ownership. |deleg
mkosiba (inactive) 2012/10/08 15:09:12 well.. the use of scoped_ptr should imply that..
joth 2012/10/09 02:13:52 Oh Yes. My eyes are still blind to the idea of pas
52 WebContents* web_contents,
53 scoped_ptr<InterceptNavigationDelegate> delegate) {
54 web_contents->SetUserData(kInterceptNavigationDelegateUserDataKey,
55 delegate.release());
56 }
57
58 // static
59 InterceptNavigationDelegate* InterceptNavigationDelegate::Get(
60 WebContents* web_contents) {
61 return reinterpret_cast<InterceptNavigationDelegate*>(
62 web_contents->GetUserData(kInterceptNavigationDelegateUserDataKey));
63 }
64
65 // static
66 content::ResourceThrottle* InterceptNavigationDelegate::CreateThrottleFor(
67 net::URLRequest* request) {
68 return new InterceptNavigationResourceThrottle(
69 request, base::Bind(&CheckIfShouldIgnoreNavigationOnUIThread));
70 }
71
72 InterceptNavigationDelegate::InterceptNavigationDelegate(
73 JNIEnv* env, jobject jdelegate)
74 : weak_jdelegate_(env, jdelegate) {
75 }
76
77 InterceptNavigationDelegate::~InterceptNavigationDelegate() {
78 }
79
80 bool InterceptNavigationDelegate::ShouldIgnoreNavigation(
81 const GURL& url,
82 bool has_user_gesture) {
83 if (!url.is_valid())
84 return false;
85
86 JNIEnv* env = base::android::AttachCurrentThread();
87 ScopedJavaLocalRef<jobject> jdelegate = weak_jdelegate_.get(env);
88
89 if (jdelegate.is_null())
90 return false;
91
92 ScopedJavaLocalRef<jstring> jstring_url =
93 ConvertUTF8ToJavaString(env, url.spec());
94 return Java_InterceptNavigationDelegate_shouldIgnoreNavigation(
95 env,
96 jdelegate.obj(),
97 jstring_url.obj(),
98 has_user_gesture);
99 }
100
101 // Register native methods.
102
103 bool RegisterInterceptNavigationDelegate(JNIEnv* env) {
104 return RegisterNativesImpl(env);
105 }
106
107 } // namespace navigation_interception
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698