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

Side by Side Diff: extensions/browser/extension_function.h

Issue 2656013005: Better crash stacktraces for ExtensionFunction bad messages. (Closed)
Patch Set: sync Created 3 years, 10 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
« no previous file with comments | « no previous file | extensions/browser/extension_function.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef EXTENSIONS_BROWSER_EXTENSION_FUNCTION_H_ 5 #ifndef EXTENSIONS_BROWSER_EXTENSION_FUNCTION_H_
6 #define EXTENSIONS_BROWSER_EXTENSION_FUNCTION_H_ 6 #define EXTENSIONS_BROWSER_EXTENSION_FUNCTION_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <list> 10 #include <list>
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 namespace extensions { 46 namespace extensions {
47 class ExtensionFunctionDispatcher; 47 class ExtensionFunctionDispatcher;
48 class IOThreadExtensionMessageFilter; 48 class IOThreadExtensionMessageFilter;
49 class QuotaLimitHeuristic; 49 class QuotaLimitHeuristic;
50 } 50 }
51 51
52 #ifdef NDEBUG 52 #ifdef NDEBUG
53 #define EXTENSION_FUNCTION_VALIDATE(test) \ 53 #define EXTENSION_FUNCTION_VALIDATE(test) \
54 do { \ 54 do { \
55 if (!(test)) { \ 55 if (!(test)) { \
56 this->set_bad_message(true); \ 56 this->SetBadMessage(); \
57 return ValidationFailure(this); \ 57 return ValidationFailure(this); \
58 } \ 58 } \
59 } while (0) 59 } while (0)
60 #else // NDEBUG 60 #else // NDEBUG
61 #define EXTENSION_FUNCTION_VALIDATE(test) CHECK(test) 61 #define EXTENSION_FUNCTION_VALIDATE(test) CHECK(test)
62 #endif // NDEBUG 62 #endif // NDEBUG
63 63
64 #ifdef NDEBUG 64 #ifdef NDEBUG
65 #define EXTENSION_FUNCTION_PRERUN_VALIDATE(test) \ 65 #define EXTENSION_FUNCTION_PRERUN_VALIDATE(test) \
66 do { \ 66 do { \
67 if (!(test)) { \ 67 if (!(test)) { \
68 this->set_bad_message(true); \ 68 this->SetBadMessage(); \
69 return false; \ 69 return false; \
70 } \ 70 } \
71 } while (0) 71 } while (0)
72 #else // NDEBUG 72 #else // NDEBUG
73 #define EXTENSION_FUNCTION_PRERUN_VALIDATE(test) CHECK(test) 73 #define EXTENSION_FUNCTION_PRERUN_VALIDATE(test) CHECK(test)
74 #endif // NDEBUG 74 #endif // NDEBUG
75 75
76 #define EXTENSION_FUNCTION_ERROR(error) \ 76 #define EXTENSION_FUNCTION_ERROR(error) \
77 do { \ 77 do { \
78 error_ = error; \ 78 error_ = error; \
79 this->set_bad_message(true); \ 79 this->SetBadMessage(); \
80 return ValidationFailure(this); \ 80 return ValidationFailure(this); \
81 } while (0) 81 } while (0)
82 82
83 // Declares a callable extension function with the given |name|. You must also 83 // Declares a callable extension function with the given |name|. You must also
84 // supply a unique |histogramvalue| used for histograms of extension function 84 // supply a unique |histogramvalue| used for histograms of extension function
85 // invocation (add new ones at the end of the enum in 85 // invocation (add new ones at the end of the enum in
86 // extension_function_histogram_value.h). 86 // extension_function_histogram_value.h).
87 #define DECLARE_EXTENSION_FUNCTION(name, histogramvalue) \ 87 #define DECLARE_EXTENSION_FUNCTION(name, histogramvalue) \
88 public: static const char* function_name() { return name; } \ 88 public: static const char* function_name() { return name; } \
89 public: static extensions::functions::HistogramValue histogram_value() \ 89 public: static extensions::functions::HistogramValue histogram_value() \
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 // Specifies the raw arguments to the function, as a JSON value. 234 // Specifies the raw arguments to the function, as a JSON value.
235 // TODO(dcheng): This should take a const ref. 235 // TODO(dcheng): This should take a const ref.
236 virtual void SetArgs(const base::ListValue* args); 236 virtual void SetArgs(const base::ListValue* args);
237 237
238 // Retrieves the results of the function as a ListValue. 238 // Retrieves the results of the function as a ListValue.
239 const base::ListValue* GetResultList() const; 239 const base::ListValue* GetResultList() const;
240 240
241 // Retrieves any error string from the function. 241 // Retrieves any error string from the function.
242 virtual const std::string& GetError() const; 242 virtual const std::string& GetError() const;
243 243
244 void set_bad_message(bool bad_message) { bad_message_ = bad_message; } 244 virtual void SetBadMessage();
245 245
246 // Specifies the name of the function. A long-lived string (such as a string 246 // Specifies the name of the function. A long-lived string (such as a string
247 // literal) must be provided. 247 // literal) must be provided.
248 void set_name(const char* name) { name_ = name; } 248 void set_name(const char* name) { name_ = name; }
249 const char* name() const { return name_; } 249 const char* name() const { return name_; }
250 250
251 void set_profile_id(void* profile_id) { profile_id_ = profile_id; } 251 void set_profile_id(void* profile_id) { profile_id_ = profile_id; }
252 void* profile_id() const { return profile_id_; } 252 void* profile_id() const { return profile_id_; }
253 253
254 void set_extension( 254 void set_extension(
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 499
500 // Extension functions that run on the UI thread. Most functions fall into 500 // Extension functions that run on the UI thread. Most functions fall into
501 // this category. 501 // this category.
502 class UIThreadExtensionFunction : public ExtensionFunction { 502 class UIThreadExtensionFunction : public ExtensionFunction {
503 public: 503 public:
504 UIThreadExtensionFunction(); 504 UIThreadExtensionFunction();
505 505
506 UIThreadExtensionFunction* AsUIThreadExtensionFunction() override; 506 UIThreadExtensionFunction* AsUIThreadExtensionFunction() override;
507 507
508 bool PreRunValidation(std::string* error) override; 508 bool PreRunValidation(std::string* error) override;
509 void SetBadMessage() final;
509 510
510 // Called when a message was received. 511 // Called when a message was received.
511 // Should return true if it processed the message. 512 // Should return true if it processed the message.
512 virtual bool OnMessageReceived(const IPC::Message& message); 513 virtual bool OnMessageReceived(const IPC::Message& message);
513 514
514 // Set the browser context which contains the extension that has originated 515 // Set the browser context which contains the extension that has originated
515 // this function call. 516 // this function call.
516 void set_browser_context(content::BrowserContext* context) { 517 void set_browser_context(content::BrowserContext* context) {
517 context_ = context; 518 context_ = context;
518 } 519 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 // a roundtrip to and from the UI thread (because communication with the 598 // a roundtrip to and from the UI thread (because communication with the
598 // extension process happens on the IO thread). It's intended to be used when 599 // extension process happens on the IO thread). It's intended to be used when
599 // performance is critical (e.g. the webRequest API which can block network 600 // performance is critical (e.g. the webRequest API which can block network
600 // requests). Generally, UIThreadExtensionFunction is more appropriate and will 601 // requests). Generally, UIThreadExtensionFunction is more appropriate and will
601 // be easier to use and interface with the rest of the browser. 602 // be easier to use and interface with the rest of the browser.
602 class IOThreadExtensionFunction : public ExtensionFunction { 603 class IOThreadExtensionFunction : public ExtensionFunction {
603 public: 604 public:
604 IOThreadExtensionFunction(); 605 IOThreadExtensionFunction();
605 606
606 IOThreadExtensionFunction* AsIOThreadExtensionFunction() override; 607 IOThreadExtensionFunction* AsIOThreadExtensionFunction() override;
608 void SetBadMessage() final;
607 609
608 void set_ipc_sender( 610 void set_ipc_sender(
609 base::WeakPtr<extensions::IOThreadExtensionMessageFilter> ipc_sender, 611 base::WeakPtr<extensions::IOThreadExtensionMessageFilter> ipc_sender,
610 int routing_id) { 612 int routing_id) {
611 ipc_sender_ = ipc_sender; 613 ipc_sender_ = ipc_sender;
612 routing_id_ = routing_id; 614 routing_id_ = routing_id;
613 } 615 }
614 616
615 base::WeakPtr<extensions::IOThreadExtensionMessageFilter> ipc_sender_weak() 617 base::WeakPtr<extensions::IOThreadExtensionMessageFilter> ipc_sender_weak()
616 const { 618 const {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 private: 691 private:
690 // If you're hitting a compile error here due to "final" - great! You're 692 // If you're hitting a compile error here due to "final" - great! You're
691 // doing the right thing, you just need to extend UIThreadExtensionFunction 693 // doing the right thing, you just need to extend UIThreadExtensionFunction
692 // instead of AsyncExtensionFunction. 694 // instead of AsyncExtensionFunction.
693 ResponseAction Run() final; 695 ResponseAction Run() final;
694 696
695 DISALLOW_COPY_AND_ASSIGN(AsyncExtensionFunction); 697 DISALLOW_COPY_AND_ASSIGN(AsyncExtensionFunction);
696 }; 698 };
697 699
698 #endif // EXTENSIONS_BROWSER_EXTENSION_FUNCTION_H_ 700 #endif // EXTENSIONS_BROWSER_EXTENSION_FUNCTION_H_
OLDNEW
« no previous file with comments | « no previous file | extensions/browser/extension_function.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698