OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/script_executor.h" | 5 #include "extensions/browser/script_executor.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/pickle.h" | 10 #include "base/pickle.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 script_observers_(AsWeakPtr(script_observers)), | 40 script_observers_(AsWeakPtr(script_observers)), |
41 extension_id_(params.extension_id), | 41 extension_id_(params.extension_id), |
42 request_id_(params.request_id), | 42 request_id_(params.request_id), |
43 callback_(callback) { | 43 callback_(callback) { |
44 content::RenderViewHost* rvh = web_contents->GetRenderViewHost(); | 44 content::RenderViewHost* rvh = web_contents->GetRenderViewHost(); |
45 rvh->Send(new ExtensionMsg_ExecuteCode(rvh->GetRoutingID(), params)); | 45 rvh->Send(new ExtensionMsg_ExecuteCode(rvh->GetRoutingID(), params)); |
46 } | 46 } |
47 | 47 |
48 virtual ~Handler() {} | 48 virtual ~Handler() {} |
49 | 49 |
50 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { | 50 virtual bool OnMessageReceived(const IPC::Message& message) override { |
51 // Unpack by hand to check the request_id, since there may be multiple | 51 // Unpack by hand to check the request_id, since there may be multiple |
52 // requests in flight but only one is for this. | 52 // requests in flight but only one is for this. |
53 if (message.type() != ExtensionHostMsg_ExecuteCodeFinished::ID) | 53 if (message.type() != ExtensionHostMsg_ExecuteCodeFinished::ID) |
54 return false; | 54 return false; |
55 | 55 |
56 int message_request_id; | 56 int message_request_id; |
57 PickleIterator iter(message); | 57 PickleIterator iter(message); |
58 CHECK(message.ReadInt(&iter, &message_request_id)); | 58 CHECK(message.ReadInt(&iter, &message_request_id)); |
59 | 59 |
60 if (message_request_id != request_id_) | 60 if (message_request_id != request_id_) |
61 return false; | 61 return false; |
62 | 62 |
63 IPC_BEGIN_MESSAGE_MAP(Handler, message) | 63 IPC_BEGIN_MESSAGE_MAP(Handler, message) |
64 IPC_MESSAGE_HANDLER(ExtensionHostMsg_ExecuteCodeFinished, | 64 IPC_MESSAGE_HANDLER(ExtensionHostMsg_ExecuteCodeFinished, |
65 OnExecuteCodeFinished) | 65 OnExecuteCodeFinished) |
66 IPC_END_MESSAGE_MAP() | 66 IPC_END_MESSAGE_MAP() |
67 return true; | 67 return true; |
68 } | 68 } |
69 | 69 |
70 virtual void WebContentsDestroyed() OVERRIDE { | 70 virtual void WebContentsDestroyed() override { |
71 base::ListValue val; | 71 base::ListValue val; |
72 callback_.Run(kRendererDestroyed, GURL(std::string()), val); | 72 callback_.Run(kRendererDestroyed, GURL(std::string()), val); |
73 delete this; | 73 delete this; |
74 } | 74 } |
75 | 75 |
76 private: | 76 private: |
77 void OnExecuteCodeFinished(int request_id, | 77 void OnExecuteCodeFinished(int request_id, |
78 const std::string& error, | 78 const std::string& error, |
79 const GURL& on_url, | 79 const GURL& on_url, |
80 const base::ListValue& script_result) { | 80 const base::ListValue& script_result) { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 params.webview_src = webview_src; | 146 params.webview_src = webview_src; |
147 params.file_url = file_url; | 147 params.file_url = file_url; |
148 params.wants_result = (result_type == JSON_SERIALIZED_RESULT); | 148 params.wants_result = (result_type == JSON_SERIALIZED_RESULT); |
149 params.user_gesture = user_gesture; | 149 params.user_gesture = user_gesture; |
150 | 150 |
151 // Handler handles IPCs and deletes itself on completion. | 151 // Handler handles IPCs and deletes itself on completion. |
152 new Handler(script_observers_, web_contents_, params, callback); | 152 new Handler(script_observers_, web_contents_, params, callback); |
153 } | 153 } |
154 | 154 |
155 } // namespace extensions | 155 } // namespace extensions |
OLD | NEW |