Chromium Code Reviews| Index: chrome/browser/android/content_view_delegate.h |
| diff --git a/chrome/browser/android/content_view_delegate.h b/chrome/browser/android/content_view_delegate.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..675b6378d99a48001b9f60d0a8aa59f19f3db07f |
| --- /dev/null |
| +++ b/chrome/browser/android/content_view_delegate.h |
| @@ -0,0 +1,84 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_ANDROID_CONTENT_VIEW_DELEGATE_H_ |
| +#define CHROME_BROWSER_ANDROID_CONTENT_VIEW_DELEGATE_H_ |
| +#pragma once |
| + |
| +#include "base/android/scoped_java_ref.h" |
| +#include "base/basictypes.h" |
| +#include "base/memory/scoped_ptr.h" |
| + |
| +class GURL; |
| + |
| +namespace content { |
| +class RenderViewHost; |
| +struct Referrer; |
| +class WebContents; |
| +} |
| + |
| +namespace net { |
| +class URLRequest; |
| +} |
| + |
| +// This provides a way of accessing select methods of the Chrome on Android |
| +// Java-side WebContents embedder from the chrome/ layer. |
| +// |
| +// It is preferable to use the static getter methods to obtain a new instance |
| +// of the class rather than holding on to one for prolonged periods of time |
| +// (see note fore more details). |
| +// |
| +// This class also provides a RenderViewHost->ContentViewDelegate mapping. |
| +// The mapping should normally be used on the UI thread only with one |
| +// exception: the ShouldInterceptRequest method, which should be called on the |
| +// IO thread. |
| +// |
| +// Note: The native ContentViewDelegate instance has a Global ref to the Java |
| +// object. By keeping the native ContentViewDelegate instance alive you're also |
| +// prolonging the lifetime of the Java instance, so don't keep a |
| +// ContentViewDelegate if you don't need to. |
| +// It is also possible that ContentViewDelegate becomes invalid when you're |
| +// holding on to it. This could happen if the WebContents is destroyed. In that |
| +// case the instance methods will noop/return default values. |
| +class ContentViewDelegate { |
|
Yaron
2012/07/10 06:34:55
Is this pulling out functionality from ContentView
|
| + public: |
| + // This will attempt to fetch the ContentViewDelegate for the given |rvh|. |
| + // This method can be called from any thread. |
| + // An empty scoped_ptr is a valid return value. |
| + static scoped_ptr<ContentViewDelegate> |
| + ForRenderViewHost(content::RenderViewHost* rvh); |
| + // This will attempt to fetch the ContentViewDelegate for the given |
| + // This method can be called from any thread. |
| + // |contents|. An empty scoped_ptr is a valid return value. |
| + static scoped_ptr<ContentViewDelegate> |
| + ForWebContents(content::WebContents* contents); |
| + |
| + static bool RegisterContentViewDelegate(JNIEnv* env); |
| + |
| + // Called for top-level navigations to decide whether the navigation should |
| + // be allowed to proceed. |
| + // This method is called on the UI thread only. |
| + bool ShouldIgnoreNavigation( |
| + content::RenderViewHost* source, |
| + const GURL& validated_url, |
| + const content::Referrer& referrer, |
| + bool is_content_initiated); |
| + |
| + // TODO(mkosiba): Stub, implement. |
| + // This method is called on the IO thread only. |
| + bool ShouldInterceptRequest(const net::URLRequest* request); |
| + |
| + ~ContentViewDelegate(); |
| + |
| + class WebContentsObserver; |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(ContentViewDelegate); |
| + |
| + ContentViewDelegate(JNIEnv* env, jobject obj); |
| + void OnWebContentsDestroyed(); |
| + |
| + base::android::ScopedJavaGlobalRef<jobject> java_object_; |
| +}; |
| + |
| +#endif // CHROME_BROWSER_ANDROID_CONTENT_VIEW_DELEGATE_H_ |