| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "android_webview/browser/aw_contents_client_bridge_base.h" | 5 #include "android_webview/browser/aw_contents_client_bridge_base.h" |
| 6 | 6 |
| 7 #include "content/public/browser/browser_thread.h" | 7 #include "content/public/browser/browser_thread.h" |
| 8 #include "content/public/browser/render_frame_host.h" | 8 #include "content/public/browser/render_frame_host.h" |
| 9 #include "content/public/browser/web_contents.h" | 9 #include "content/public/browser/web_contents.h" |
| 10 | 10 |
| 11 using content::BrowserThread; | 11 using content::BrowserThread; |
| 12 using content::WebContents; | 12 using content::WebContents; |
| 13 | 13 |
| 14 namespace android_webview { | 14 namespace android_webview { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 const void* kAwContentsClientBridgeBase = &kAwContentsClientBridgeBase; | 18 const void* const kAwContentsClientBridgeBase = &kAwContentsClientBridgeBase; |
| 19 | 19 |
| 20 // This class is invented so that the UserData registry that we inject the | 20 // This class is invented so that the UserData registry that we inject the |
| 21 // AwContentsClientBridgeBase object does not own and destroy it. | 21 // AwContentsClientBridgeBase object does not own and destroy it. |
| 22 class UserData : public base::SupportsUserData::Data { | 22 class UserData : public base::SupportsUserData::Data { |
| 23 public: | 23 public: |
| 24 static AwContentsClientBridgeBase* GetContents( | 24 static AwContentsClientBridgeBase* GetContents( |
| 25 content::WebContents* web_contents) { | 25 content::WebContents* web_contents) { |
| 26 if (!web_contents) | 26 if (!web_contents) |
| 27 return NULL; | 27 return NULL; |
| 28 UserData* data = static_cast<UserData*>( | 28 UserData* data = static_cast<UserData*>( |
| 29 web_contents->GetUserData(kAwContentsClientBridgeBase)); | 29 web_contents->GetUserData(kAwContentsClientBridgeBase)); |
| 30 return data ? data->contents_ : NULL; | 30 return data ? data->contents_ : NULL; |
| 31 } | 31 } |
| 32 | 32 |
| 33 explicit UserData(AwContentsClientBridgeBase* ptr) : contents_(ptr) {} | 33 explicit UserData(AwContentsClientBridgeBase* ptr) : contents_(ptr) {} |
| 34 private: | 34 private: |
| 35 AwContentsClientBridgeBase* contents_; | 35 AwContentsClientBridgeBase* contents_; |
| 36 | 36 |
| 37 DISALLOW_COPY_AND_ASSIGN(UserData); | 37 DISALLOW_COPY_AND_ASSIGN(UserData); |
| 38 }; | 38 }; |
| 39 | 39 |
| 40 } // namespace | 40 } // namespace |
| 41 | 41 |
| 42 // static | 42 // static |
| 43 void AwContentsClientBridgeBase::Associate( | 43 void AwContentsClientBridgeBase::Associate( |
| 44 WebContents* web_contents, | 44 WebContents* web_contents, |
| 45 AwContentsClientBridgeBase* handler) { | 45 AwContentsClientBridgeBase* handler) { |
| 46 web_contents->SetUserData(kAwContentsClientBridgeBase, | 46 web_contents->SetUserData(kAwContentsClientBridgeBase, |
| 47 new UserData(handler)); | 47 new UserData(handler)); |
| 48 } | 48 } |
| 49 | 49 |
| 50 // static | 50 // static |
| (...skipping 11 matching lines...) Expand all Loading... |
| 62 content::RenderFrameHost::FromID(render_process_id, render_frame_id); | 62 content::RenderFrameHost::FromID(render_process_id, render_frame_id); |
| 63 content::WebContents* web_contents = | 63 content::WebContents* web_contents = |
| 64 content::WebContents::FromRenderFrameHost(rfh); | 64 content::WebContents::FromRenderFrameHost(rfh); |
| 65 return UserData::GetContents(web_contents); | 65 return UserData::GetContents(web_contents); |
| 66 } | 66 } |
| 67 | 67 |
| 68 AwContentsClientBridgeBase::~AwContentsClientBridgeBase() { | 68 AwContentsClientBridgeBase::~AwContentsClientBridgeBase() { |
| 69 } | 69 } |
| 70 | 70 |
| 71 } // namespace android_webview | 71 } // namespace android_webview |
| OLD | NEW |