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

Side by Side Diff: content/components/navigation_interception/intercept_navigation_delegate.cc

Issue 11830043: Move content/components/navigation_interception to src/components (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase Created 7 years, 11 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
(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 "content/components/navigation_interception/intercept_navigation_delega te.h"
6
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h"
9 #include "base/callback.h"
10 #include "content/components/navigation_interception/intercept_navigation_resour ce_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 content {
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 is_post,
35 bool has_user_gesture,
36 PageTransition transition_type) {
37 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
38 DCHECK(source);
39
40 WebContents* web_contents = WebContents::FromRenderViewHost(source);
41 if (!web_contents)
42 return false;
43 InterceptNavigationDelegate* intercept_navigation_delegate =
44 InterceptNavigationDelegate::Get(web_contents);
45 if (!intercept_navigation_delegate)
46 return false;
47
48 return intercept_navigation_delegate->ShouldIgnoreNavigation(
49 url, is_post, has_user_gesture, transition_type);
50 }
51
52 } // namespace
53
54 // static
55 void InterceptNavigationDelegate::Associate(
56 WebContents* web_contents,
57 scoped_ptr<InterceptNavigationDelegate> delegate) {
58 web_contents->SetUserData(kInterceptNavigationDelegateUserDataKey,
59 delegate.release());
60 }
61
62 // static
63 InterceptNavigationDelegate* InterceptNavigationDelegate::Get(
64 WebContents* web_contents) {
65 return reinterpret_cast<InterceptNavigationDelegate*>(
66 web_contents->GetUserData(kInterceptNavigationDelegateUserDataKey));
67 }
68
69 // static
70 content::ResourceThrottle* InterceptNavigationDelegate::CreateThrottleFor(
71 net::URLRequest* request) {
72 return new InterceptNavigationResourceThrottle(
73 request, base::Bind(&CheckIfShouldIgnoreNavigationOnUIThread));
74 }
75
76 InterceptNavigationDelegate::InterceptNavigationDelegate(
77 JNIEnv* env, jobject jdelegate)
78 : weak_jdelegate_(env, jdelegate) {
79 }
80
81 InterceptNavigationDelegate::~InterceptNavigationDelegate() {
82 }
83
84 bool InterceptNavigationDelegate::ShouldIgnoreNavigation(
85 const GURL& url,
86 bool is_post,
87 bool has_user_gesture,
88 PageTransition transition_type) {
89 if (!url.is_valid())
90 return false;
91
92 JNIEnv* env = base::android::AttachCurrentThread();
93 ScopedJavaLocalRef<jobject> jdelegate = weak_jdelegate_.get(env);
94
95 if (jdelegate.is_null())
96 return false;
97
98 ScopedJavaLocalRef<jstring> jstring_url =
99 ConvertUTF8ToJavaString(env, url.spec());
100 return Java_InterceptNavigationDelegate_shouldIgnoreNavigation(
101 env,
102 jdelegate.obj(),
103 jstring_url.obj(),
104 is_post,
105 has_user_gesture,
106 transition_type);
107 }
108
109 // Register native methods.
110
111 bool RegisterInterceptNavigationDelegate(JNIEnv* env) {
112 return RegisterNativesImpl(env);
113 }
114
115 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698