OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "extensions/browser/extension_function.h" | 5 #include "extensions/browser/extension_function.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "content/public/browser/notification_source.h" | 8 #include "content/public/browser/notification_source.h" |
9 #include "content/public/browser/notification_types.h" | 9 #include "content/public/browser/notification_types.h" |
10 #include "content/public/browser/render_frame_host.h" | 10 #include "content/public/browser/render_frame_host.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 } else { | 44 } else { |
45 function->SetResultList(result.Pass()); | 45 function->SetResultList(result.Pass()); |
46 } | 46 } |
47 // It would be nice to DCHECK(error.empty()) but some legacy extension | 47 // It would be nice to DCHECK(error.empty()) but some legacy extension |
48 // function implementations... I'm looking at chrome.input.ime... do this | 48 // function implementations... I'm looking at chrome.input.ime... do this |
49 // for some reason. | 49 // for some reason. |
50 } | 50 } |
51 | 51 |
52 virtual ~ArgumentListResponseValue() {} | 52 virtual ~ArgumentListResponseValue() {} |
53 | 53 |
54 virtual bool Apply() OVERRIDE { return true; } | 54 virtual bool Apply() override { return true; } |
55 | 55 |
56 private: | 56 private: |
57 std::string function_name_; | 57 std::string function_name_; |
58 const char* title_; | 58 const char* title_; |
59 }; | 59 }; |
60 | 60 |
61 class ErrorResponseValue : public ExtensionFunction::ResponseValueObject { | 61 class ErrorResponseValue : public ExtensionFunction::ResponseValueObject { |
62 public: | 62 public: |
63 ErrorResponseValue(ExtensionFunction* function, const std::string& error) { | 63 ErrorResponseValue(ExtensionFunction* function, const std::string& error) { |
64 // It would be nice to DCHECK(!error.empty()) but too many legacy extension | 64 // It would be nice to DCHECK(!error.empty()) but too many legacy extension |
65 // function implementations don't set error but signal failure. | 65 // function implementations don't set error but signal failure. |
66 function->SetError(error); | 66 function->SetError(error); |
67 } | 67 } |
68 | 68 |
69 virtual ~ErrorResponseValue() {} | 69 virtual ~ErrorResponseValue() {} |
70 | 70 |
71 virtual bool Apply() OVERRIDE { return false; } | 71 virtual bool Apply() override { return false; } |
72 }; | 72 }; |
73 | 73 |
74 class BadMessageResponseValue : public ExtensionFunction::ResponseValueObject { | 74 class BadMessageResponseValue : public ExtensionFunction::ResponseValueObject { |
75 public: | 75 public: |
76 explicit BadMessageResponseValue(ExtensionFunction* function) { | 76 explicit BadMessageResponseValue(ExtensionFunction* function) { |
77 function->set_bad_message(true); | 77 function->set_bad_message(true); |
78 NOTREACHED() << function->name() << ": bad message"; | 78 NOTREACHED() << function->name() << ": bad message"; |
79 } | 79 } |
80 | 80 |
81 virtual ~BadMessageResponseValue() {} | 81 virtual ~BadMessageResponseValue() {} |
82 | 82 |
83 virtual bool Apply() OVERRIDE { return false; } | 83 virtual bool Apply() override { return false; } |
84 }; | 84 }; |
85 | 85 |
86 class RespondNowAction : public ExtensionFunction::ResponseActionObject { | 86 class RespondNowAction : public ExtensionFunction::ResponseActionObject { |
87 public: | 87 public: |
88 typedef base::Callback<void(bool)> SendResponseCallback; | 88 typedef base::Callback<void(bool)> SendResponseCallback; |
89 RespondNowAction(ExtensionFunction::ResponseValue result, | 89 RespondNowAction(ExtensionFunction::ResponseValue result, |
90 const SendResponseCallback& send_response) | 90 const SendResponseCallback& send_response) |
91 : result_(result.Pass()), send_response_(send_response) {} | 91 : result_(result.Pass()), send_response_(send_response) {} |
92 virtual ~RespondNowAction() {} | 92 virtual ~RespondNowAction() {} |
93 | 93 |
94 virtual void Execute() OVERRIDE { send_response_.Run(result_->Apply()); } | 94 virtual void Execute() override { send_response_.Run(result_->Apply()); } |
95 | 95 |
96 private: | 96 private: |
97 ExtensionFunction::ResponseValue result_; | 97 ExtensionFunction::ResponseValue result_; |
98 SendResponseCallback send_response_; | 98 SendResponseCallback send_response_; |
99 }; | 99 }; |
100 | 100 |
101 class RespondLaterAction : public ExtensionFunction::ResponseActionObject { | 101 class RespondLaterAction : public ExtensionFunction::ResponseActionObject { |
102 public: | 102 public: |
103 virtual ~RespondLaterAction() {} | 103 virtual ~RespondLaterAction() {} |
104 | 104 |
105 virtual void Execute() OVERRIDE {} | 105 virtual void Execute() override {} |
106 }; | 106 }; |
107 | 107 |
108 } // namespace | 108 } // namespace |
109 | 109 |
110 // static | 110 // static |
111 void ExtensionFunctionDeleteTraits::Destruct(const ExtensionFunction* x) { | 111 void ExtensionFunctionDeleteTraits::Destruct(const ExtensionFunction* x) { |
112 x->Destruct(); | 112 x->Destruct(); |
113 } | 113 } |
114 | 114 |
115 // Helper class to track the lifetime of ExtensionFunction's RenderViewHost or | 115 // Helper class to track the lifetime of ExtensionFunction's RenderViewHost or |
116 // RenderFrameHost pointer and NULL it out when it dies. It also allows us to | 116 // RenderFrameHost pointer and NULL it out when it dies. It also allows us to |
117 // filter IPC messages coming from the RenderViewHost/RenderFrameHost. | 117 // filter IPC messages coming from the RenderViewHost/RenderFrameHost. |
118 class UIThreadExtensionFunction::RenderHostTracker | 118 class UIThreadExtensionFunction::RenderHostTracker |
119 : public content::WebContentsObserver { | 119 : public content::WebContentsObserver { |
120 public: | 120 public: |
121 explicit RenderHostTracker(UIThreadExtensionFunction* function) | 121 explicit RenderHostTracker(UIThreadExtensionFunction* function) |
122 : content::WebContentsObserver( | 122 : content::WebContentsObserver( |
123 function->render_view_host() ? | 123 function->render_view_host() ? |
124 WebContents::FromRenderViewHost(function->render_view_host()) : | 124 WebContents::FromRenderViewHost(function->render_view_host()) : |
125 WebContents::FromRenderFrameHost( | 125 WebContents::FromRenderFrameHost( |
126 function->render_frame_host())), | 126 function->render_frame_host())), |
127 function_(function) { | 127 function_(function) { |
128 } | 128 } |
129 | 129 |
130 private: | 130 private: |
131 // content::WebContentsObserver: | 131 // content::WebContentsObserver: |
132 virtual void RenderViewDeleted( | 132 virtual void RenderViewDeleted( |
133 content::RenderViewHost* render_view_host) OVERRIDE { | 133 content::RenderViewHost* render_view_host) override { |
134 if (render_view_host != function_->render_view_host()) | 134 if (render_view_host != function_->render_view_host()) |
135 return; | 135 return; |
136 | 136 |
137 function_->SetRenderViewHost(NULL); | 137 function_->SetRenderViewHost(NULL); |
138 } | 138 } |
139 virtual void RenderFrameDeleted( | 139 virtual void RenderFrameDeleted( |
140 content::RenderFrameHost* render_frame_host) OVERRIDE { | 140 content::RenderFrameHost* render_frame_host) override { |
141 if (render_frame_host != function_->render_frame_host()) | 141 if (render_frame_host != function_->render_frame_host()) |
142 return; | 142 return; |
143 | 143 |
144 function_->SetRenderFrameHost(NULL); | 144 function_->SetRenderFrameHost(NULL); |
145 } | 145 } |
146 | 146 |
147 virtual bool OnMessageReceived( | 147 virtual bool OnMessageReceived( |
148 const IPC::Message& message, | 148 const IPC::Message& message, |
149 content::RenderFrameHost* render_frame_host) OVERRIDE { | 149 content::RenderFrameHost* render_frame_host) override { |
150 DCHECK(render_frame_host); | 150 DCHECK(render_frame_host); |
151 if (render_frame_host == function_->render_frame_host()) | 151 if (render_frame_host == function_->render_frame_host()) |
152 return function_->OnMessageReceived(message); | 152 return function_->OnMessageReceived(message); |
153 else | 153 else |
154 return false; | 154 return false; |
155 } | 155 } |
156 | 156 |
157 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { | 157 virtual bool OnMessageReceived(const IPC::Message& message) override { |
158 return function_->OnMessageReceived(message); | 158 return function_->OnMessageReceived(message); |
159 } | 159 } |
160 | 160 |
161 UIThreadExtensionFunction* function_; | 161 UIThreadExtensionFunction* function_; |
162 | 162 |
163 DISALLOW_COPY_AND_ASSIGN(RenderHostTracker); | 163 DISALLOW_COPY_AND_ASSIGN(RenderHostTracker); |
164 }; | 164 }; |
165 | 165 |
166 ExtensionFunction::ExtensionFunction() | 166 ExtensionFunction::ExtensionFunction() |
167 : request_id_(-1), | 167 : request_id_(-1), |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 | 481 |
482 ExtensionFunction::ResponseAction SyncIOThreadExtensionFunction::Run() { | 482 ExtensionFunction::ResponseAction SyncIOThreadExtensionFunction::Run() { |
483 return RespondNow(RunSync() ? ArgumentList(results_.Pass()) : Error(error_)); | 483 return RespondNow(RunSync() ? ArgumentList(results_.Pass()) : Error(error_)); |
484 } | 484 } |
485 | 485 |
486 // static | 486 // static |
487 bool SyncIOThreadExtensionFunction::ValidationFailure( | 487 bool SyncIOThreadExtensionFunction::ValidationFailure( |
488 SyncIOThreadExtensionFunction* function) { | 488 SyncIOThreadExtensionFunction* function) { |
489 return false; | 489 return false; |
490 } | 490 } |
OLD | NEW |