From 39e615ed87da2f5a8eee87ca9b5b027f740ebf10 Mon Sep 17 00:00:00 2001 From: Robo Date: Thu, 17 Dec 2015 22:57:56 +0530 Subject: [PATCH 1/3] webContents: adding findInPage api --- atom/browser/api/atom_api_web_contents.cc | 51 +++++++++++++++++++ atom/browser/api/atom_api_web_contents.h | 8 +++ .../native_mate_converters/blink_converter.cc | 16 ++++++ .../native_mate_converters/blink_converter.h | 7 +++ .../content_converter.cc | 20 ++++++++ .../content_converter.h | 7 +++ docs/api/web-contents.md | 49 +++++++++++++++++- 7 files changed, 157 insertions(+), 1 deletion(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 82227d70322a..8c24ea1a825f 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -49,6 +49,7 @@ #include "content/public/browser/site_instance.h" #include "content/public/browser/web_contents.h" #include "content/public/common/context_menu_params.h" +#include "native_mate/converter.h" #include "native_mate/dictionary.h" #include "native_mate/object_template_builder.h" #include "net/http/http_response_headers.h" @@ -426,6 +427,29 @@ bool WebContents::OnGoToEntryOffset(int offset) { return false; } +void WebContents::FindReply(content::WebContents* web_contents, + int request_id, + int number_of_matches, + const gfx::Rect& selection_rect, + int active_match_ordinal, + bool final_update) { + v8::Locker locker(isolate()); + v8::HandleScope handle_scope(isolate()); + + mate::Dictionary result = mate::Dictionary::CreateEmpty(isolate()); + if (number_of_matches == -1) { + result.Set("requestId", request_id); + result.Set("selectionArea", selection_rect); + result.Set("finalUpdate", final_update); + Emit("find-in-page-response", result); + } else if (final_update) { + result.Set("requestId", request_id); + result.Set("matches", number_of_matches); + result.Set("finalUpdate", final_update); + Emit("find-in-page-response", result); + } +} + void WebContents::BeforeUnloadFired(const base::TimeTicks& proceed_time) { // Do nothing, we override this method just to avoid compilation error since // there are two virtual functions named BeforeUnloadFired. @@ -902,6 +926,31 @@ void WebContents::ReplaceMisspelling(const base::string16& word) { web_contents()->ReplaceMisspelling(word); } +void WebContents::FindInPage(mate::Arguments* args) { + int request_id; + base::string16 search_text; + blink::WebFindOptions options; + if (!args->GetNext(&request_id)) { + args->ThrowError("Must provide a request id"); + return; + } + + if (!args->GetNext(&search_text)) { + args->ThrowError("Must provide a non-empty search content"); + return; + } + + args->GetNext(&options); + + web_contents()->Find(request_id, search_text, options); + web_contents()->GetMainFrame() + ->ActivateFindInPageResultForAccessibility(request_id); +} + +void WebContents::StopFindInPage(content::StopFindAction action) { + web_contents()->StopFinding(action); +} + void WebContents::Focus() { web_contents()->Focus(); } @@ -1048,6 +1097,8 @@ void WebContents::BuildPrototype(v8::Isolate* isolate, .SetMethod("unselect", &WebContents::Unselect) .SetMethod("replace", &WebContents::Replace) .SetMethod("replaceMisspelling", &WebContents::ReplaceMisspelling) + .SetMethod("findInPage", &WebContents::FindInPage) + .SetMethod("stopFindInPage", &WebContents::StopFindInPage) .SetMethod("focus", &WebContents::Focus) .SetMethod("tabTraverse", &WebContents::TabTraverse) .SetMethod("_send", &WebContents::SendIPCMessage) diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index 0173b9de0c1f..d78455608dd5 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -110,6 +110,8 @@ class WebContents : public mate::TrackableObject, void Unselect(); void Replace(const base::string16& word); void ReplaceMisspelling(const base::string16& word); + void FindInPage(mate::Arguments* args); + void StopFindInPage(content::StopFindAction action); // Focus. void Focus(); @@ -187,6 +189,12 @@ class WebContents : public mate::TrackableObject, void RendererResponsive(content::WebContents* source) override; bool HandleContextMenu(const content::ContextMenuParams& params) override; bool OnGoToEntryOffset(int offset) override; + void FindReply(content::WebContents* web_contents, + int request_id, + int number_of_matches, + const gfx::Rect& selection_rect, + int active_match_ordinal, + bool final_update) override; // content::WebContentsObserver: void BeforeUnloadFired(const base::TimeTicks& proceed_time) override; diff --git a/atom/common/native_mate_converters/blink_converter.cc b/atom/common/native_mate_converters/blink_converter.cc index d192018da012..71a2ac977820 100644 --- a/atom/common/native_mate_converters/blink_converter.cc +++ b/atom/common/native_mate_converters/blink_converter.cc @@ -282,4 +282,20 @@ bool Converter::FromV8( return true; } +bool Converter::FromV8( + v8::Isolate* isolate, + v8::Local val, + blink::WebFindOptions* out) { + mate::Dictionary dict; + if (!ConvertFromV8(isolate, val, &dict)) + return false; + + dict.Get("forward", &out->forward); + dict.Get("matchCase", &out->matchCase); + dict.Get("findNext", &out->findNext); + dict.Get("wordStart", &out->wordStart); + dict.Get("medialCapitalAsWordStart", &out->medialCapitalAsWordStart); + return true; +} + } // namespace mate diff --git a/atom/common/native_mate_converters/blink_converter.h b/atom/common/native_mate_converters/blink_converter.h index 17bb108d349e..9f58659a3a59 100644 --- a/atom/common/native_mate_converters/blink_converter.h +++ b/atom/common/native_mate_converters/blink_converter.h @@ -6,6 +6,7 @@ #define ATOM_COMMON_NATIVE_MATE_CONVERTERS_BLINK_CONVERTER_H_ #include "native_mate/converter.h" +#include "third_party/WebKit/public/web/WebFindOptions.h" namespace blink { class WebInputEvent; @@ -80,6 +81,12 @@ struct Converter { blink::WebDeviceEmulationParams* out); }; +template<> +struct Converter { + static bool FromV8(v8::Isolate* isolate, v8::Local val, + blink::WebFindOptions* out); +}; + } // namespace mate #endif // ATOM_COMMON_NATIVE_MATE_CONVERTERS_BLINK_CONVERTER_H_ diff --git a/atom/common/native_mate_converters/content_converter.cc b/atom/common/native_mate_converters/content_converter.cc index 15a57dea5fb8..41d19e39691f 100644 --- a/atom/common/native_mate_converters/content_converter.cc +++ b/atom/common/native_mate_converters/content_converter.cc @@ -4,6 +4,7 @@ #include "atom/common/native_mate_converters/content_converter.h" +#include #include #include "atom/common/native_mate_converters/callback.h" @@ -97,4 +98,23 @@ v8::Local Converter::ToV8( return mate::ConvertToV8(isolate, dict); } +// static +bool Converter::FromV8( + v8::Isolate* isolate, + v8::Local val, + content::StopFindAction* out) { + std::string action; + if (!ConvertFromV8(isolate, val, &action)) + return false; + + if (action == "clearSelection") + *out = content::STOP_FIND_ACTION_CLEAR_SELECTION; + else if (action == "keepSelection") + *out = content::STOP_FIND_ACTION_KEEP_SELECTION; + else + *out = content::STOP_FIND_ACTION_ACTIVATE_SELECTION; + + return true; +} + } // namespace mate diff --git a/atom/common/native_mate_converters/content_converter.h b/atom/common/native_mate_converters/content_converter.h index 7edee24fa142..a5708e022b57 100644 --- a/atom/common/native_mate_converters/content_converter.h +++ b/atom/common/native_mate_converters/content_converter.h @@ -8,6 +8,7 @@ #include #include "content/public/common/menu_item.h" +#include "content/public/common/stop_find_action.h" #include "native_mate/converter.h" namespace content { @@ -32,6 +33,12 @@ struct Converter { const ContextMenuParamsWithWebContents& val); }; +template<> +struct Converter { + static bool FromV8(v8::Isolate* isolate, v8::Local val, + content::StopFindAction* out); +}; + } // namespace mate #endif // ATOM_COMMON_NATIVE_MATE_CONVERTERS_CONTENT_CONVERTER_H_ diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index abb038ac1ab2..4d7907c0f855 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -229,6 +229,20 @@ Emitted when media starts playing. Emitted when media is paused or done playing. +### Event: 'find-in-page-response' + +Returns: + +* `event` Event +* `result` Object + * `requestId` Integer + * `matches` Integer __Optional__ - Number of Matches. + * `selectionArea` Object __Optional__ - Coordinates of first match region. + * `finalUpdate` Boolean - Indicates if more responses are to follow. + +Emitted when a result is available for +[`webContents.findInPage`](web-contents.md#webcontentsfindinpage) request. + ## Instance Methods The `webContents` object has the following instance methods: @@ -420,6 +434,39 @@ Executes the editing command `replace` in web page. Executes the editing command `replaceMisspelling` in web page. +### `webContents.findInPage(id, text[, options])` + +* `id` Integer +* `text` String - Content to be searched, must not be empty. +* `options` Object __Optional__ + * `forward` Boolean - Whether to search forward or backward. + * `findNext` Boolean - Whether the operation is first request or a follow up. + * `matchCase` Boolean - Whether search should be case-sensitive. + * `wordStart` Boolean - Whether to look only at the start of words. + * ` medialCapitalAsWordStart` Boolean - When combined with `wordStart`, + accepts a match in the middle of a word if the match begins with an + uppercase letter followed by a lowercase or non-letter. + Accepts several other intra-word matches + +Finds all matches for the `text` in the web page. + +### `webContents.stopFindInPage(action)` + +* `action` String - Should be called with either `clearSelection` or `keepSelection`. + By default it keeps the last selection. + +Stops any `findInPage` request for the `webContents` +with the provided `action`. + +```javascript +webContents.on('find-in-page-response', function(event, result) { + if (result.finalUpdate) + webContents.stopFindInPage("clearSelection"); +}); + +webContents.findInPage(1, "api"); +```. + ### `webContents.hasServiceWorker(callback)` * `callback` Function @@ -462,7 +509,7 @@ size. * 1 - none * 2 - minimum * `pageSize` String - Specify page size of the generated PDF. - * `A5` + * `A5` * `A4` * `A3` * `Legal` From d162180196a87f0029aa0420d1e15f4157c62d3c Mon Sep 17 00:00:00 2001 From: Robo Date: Fri, 18 Dec 2015 04:40:42 +0530 Subject: [PATCH 2/3] add api to webview --- atom/browser/api/atom_api_web_contents.cc | 23 ++++---- atom/browser/api/atom_api_web_contents.h | 9 +++- atom/browser/lib/guest-view-manager.coffee | 7 +-- .../native_mate_converters/blink_converter.cc | 1 + .../native_mate_converters/blink_converter.h | 2 +- .../content_converter.cc | 4 +- .../lib/web-view/guest-view-internal.coffee | 1 + atom/renderer/lib/web-view/web-view.coffee | 2 + docs/api/web-contents.md | 44 +++++++++------- docs/api/web-view-tag.md | 52 +++++++++++++++++++ spec/fixtures/pages/content.html | 16 ++++++ spec/webview-spec.coffee | 16 ++++++ 12 files changed, 138 insertions(+), 39 deletions(-) create mode 100644 spec/fixtures/pages/content.html diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 8c24ea1a825f..995774376e96 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -225,7 +225,8 @@ WebContents::WebContents(content::WebContents* web_contents) } WebContents::WebContents(v8::Isolate* isolate, - const mate::Dictionary& options) { + const mate::Dictionary& options) + : request_id_(0) { // Whether it is a guest WebContents. bool is_guest = false; options.Get("isGuest", &is_guest); @@ -441,12 +442,12 @@ void WebContents::FindReply(content::WebContents* web_contents, result.Set("requestId", request_id); result.Set("selectionArea", selection_rect); result.Set("finalUpdate", final_update); - Emit("find-in-page-response", result); + Emit("found-in-page", result); } else if (final_update) { result.Set("requestId", request_id); result.Set("matches", number_of_matches); result.Set("finalUpdate", final_update); - Emit("find-in-page-response", result); + Emit("found-in-page", result); } } @@ -926,25 +927,19 @@ void WebContents::ReplaceMisspelling(const base::string16& word) { web_contents()->ReplaceMisspelling(word); } -void WebContents::FindInPage(mate::Arguments* args) { - int request_id; +uint32 WebContents::FindInPage(mate::Arguments* args) { + uint32 request_id = GetNextRequestId(); base::string16 search_text; blink::WebFindOptions options; - if (!args->GetNext(&request_id)) { - args->ThrowError("Must provide a request id"); - return; - } - - if (!args->GetNext(&search_text)) { + if (!args->GetNext(&search_text) || search_text.empty()) { args->ThrowError("Must provide a non-empty search content"); - return; + return 0; } args->GetNext(&options); web_contents()->Find(request_id, search_text, options); - web_contents()->GetMainFrame() - ->ActivateFindInPageResultForAccessibility(request_id); + return request_id; } void WebContents::StopFindInPage(content::StopFindAction action) { diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index d78455608dd5..0c7f129bd2c0 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -110,7 +110,7 @@ class WebContents : public mate::TrackableObject, void Unselect(); void Replace(const base::string16& word); void ReplaceMisspelling(const base::string16& word); - void FindInPage(mate::Arguments* args); + uint32 FindInPage(mate::Arguments* args); void StopFindInPage(content::StopFindAction action); // Focus. @@ -250,6 +250,10 @@ class WebContents : public mate::TrackableObject, AtomBrowserContext* GetBrowserContext() const; + uint32 GetNextRequestId() { + return ++request_id_; + } + // Called when received a message from renderer. void OnRendererMessage(const base::string16& channel, const base::ListValue& args); @@ -271,6 +275,9 @@ class WebContents : public mate::TrackableObject, // The type of current WebContents. Type type_; + // Request id used for findInPage request. + uint32 request_id_; + DISALLOW_COPY_AND_ASSIGN(WebContents); }; diff --git a/atom/browser/lib/guest-view-manager.coffee b/atom/browser/lib/guest-view-manager.coffee index 335d6516fc37..17308f4ce12b 100644 --- a/atom/browser/lib/guest-view-manager.coffee +++ b/atom/browser/lib/guest-view-manager.coffee @@ -22,9 +22,10 @@ supportedWebViewEvents = [ 'page-title-updated' 'page-favicon-updated' 'enter-html-full-screen' - 'leave-html-full-screen', - 'media-started-playing', - 'media-paused', + 'leave-html-full-screen' + 'media-started-playing' + 'media-paused' + 'found-in-page' ] nextInstanceId = 0 diff --git a/atom/common/native_mate_converters/blink_converter.cc b/atom/common/native_mate_converters/blink_converter.cc index 71a2ac977820..095490ab883c 100644 --- a/atom/common/native_mate_converters/blink_converter.cc +++ b/atom/common/native_mate_converters/blink_converter.cc @@ -13,6 +13,7 @@ #include "content/public/browser/native_web_keyboard_event.h" #include "native_mate/dictionary.h" #include "third_party/WebKit/public/web/WebDeviceEmulationParams.h" +#include "third_party/WebKit/public/web/WebFindOptions.h" #include "third_party/WebKit/public/web/WebInputEvent.h" namespace { diff --git a/atom/common/native_mate_converters/blink_converter.h b/atom/common/native_mate_converters/blink_converter.h index 9f58659a3a59..5e715c631783 100644 --- a/atom/common/native_mate_converters/blink_converter.h +++ b/atom/common/native_mate_converters/blink_converter.h @@ -6,7 +6,6 @@ #define ATOM_COMMON_NATIVE_MATE_CONVERTERS_BLINK_CONVERTER_H_ #include "native_mate/converter.h" -#include "third_party/WebKit/public/web/WebFindOptions.h" namespace blink { class WebInputEvent; @@ -14,6 +13,7 @@ class WebMouseEvent; class WebMouseWheelEvent; class WebKeyboardEvent; struct WebDeviceEmulationParams; +struct WebFindOptions; struct WebFloatPoint; struct WebPoint; struct WebSize; diff --git a/atom/common/native_mate_converters/content_converter.cc b/atom/common/native_mate_converters/content_converter.cc index 41d19e39691f..d79094f79d43 100644 --- a/atom/common/native_mate_converters/content_converter.cc +++ b/atom/common/native_mate_converters/content_converter.cc @@ -111,8 +111,10 @@ bool Converter::FromV8( *out = content::STOP_FIND_ACTION_CLEAR_SELECTION; else if (action == "keepSelection") *out = content::STOP_FIND_ACTION_KEEP_SELECTION; - else + else if (action == "activateSelection") *out = content::STOP_FIND_ACTION_ACTIVATE_SELECTION; + else + return false; return true; } diff --git a/atom/renderer/lib/web-view/guest-view-internal.coffee b/atom/renderer/lib/web-view/guest-view-internal.coffee index 04fa707da764..9178b3273dd5 100644 --- a/atom/renderer/lib/web-view/guest-view-internal.coffee +++ b/atom/renderer/lib/web-view/guest-view-internal.coffee @@ -27,6 +27,7 @@ WEB_VIEW_EVENTS = 'page-favicon-updated': ['favicons'] 'enter-html-full-screen': [] 'leave-html-full-screen': [] + 'found-in-page': ['result'] DEPRECATED_EVENTS = 'page-title-updated': 'page-title-set' diff --git a/atom/renderer/lib/web-view/web-view.coffee b/atom/renderer/lib/web-view/web-view.coffee index da36886f6ffa..2d81bd6aa6e9 100644 --- a/atom/renderer/lib/web-view/web-view.coffee +++ b/atom/renderer/lib/web-view/web-view.coffee @@ -287,6 +287,8 @@ registerWebViewElement = -> 'unselect' 'replace' 'replaceMisspelling' + 'findInPage' + 'stopFindInPage' 'getId' 'downloadURL' 'inspectServiceWorker' diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index 4d7907c0f855..3d903a8414d8 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -229,16 +229,16 @@ Emitted when media starts playing. Emitted when media is paused or done playing. -### Event: 'find-in-page-response' +### Event: 'found-in-page' Returns: * `event` Event * `result` Object * `requestId` Integer - * `matches` Integer __Optional__ - Number of Matches. - * `selectionArea` Object __Optional__ - Coordinates of first match region. * `finalUpdate` Boolean - Indicates if more responses are to follow. + * `matches` Integer (Optional) - Number of Matches. + * `selectionArea` Object (Optional) - Coordinates of first match region. Emitted when a result is available for [`webContents.findInPage`](web-contents.md#webcontentsfindinpage) request. @@ -434,38 +434,44 @@ Executes the editing command `replace` in web page. Executes the editing command `replaceMisspelling` in web page. -### `webContents.findInPage(id, text[, options])` +### `webContents.findInPage(text[, options])` -* `id` Integer * `text` String - Content to be searched, must not be empty. -* `options` Object __Optional__ - * `forward` Boolean - Whether to search forward or backward. - * `findNext` Boolean - Whether the operation is first request or a follow up. - * `matchCase` Boolean - Whether search should be case-sensitive. +* `options` Object (Optional) + * `forward` Boolean - Whether to search forward or backward, defaults to `true`. + * `findNext` Boolean - Whether the operation is first request or a follow up, + defaults to `false`. + * `matchCase` Boolean - Whether search should be case-sensitive, + defaults to `false`. * `wordStart` Boolean - Whether to look only at the start of words. - * ` medialCapitalAsWordStart` Boolean - When combined with `wordStart`, + defaults to `false`. + * `medialCapitalAsWordStart` Boolean - When combined with `wordStart`, accepts a match in the middle of a word if the match begins with an uppercase letter followed by a lowercase or non-letter. - Accepts several other intra-word matches + Accepts several other intra-word matches, defaults to `false`. -Finds all matches for the `text` in the web page. +Starts a request to find all matches for the `text` in the web page and returns an `Integer` +representing the request id used for the request. The result of the request can be +obtained by subscribing to [`found-in-page`](web-contents.md#event-found-in-page) event. ### `webContents.stopFindInPage(action)` -* `action` String - Should be called with either `clearSelection` or `keepSelection`. - By default it keeps the last selection. +* `action` String - Specifies the action to take place when ending + [`webContents.findInPage `](web-contents.md#webcontentfindinpage) request. + * `clearSelection` - Translate the selection into a normal selection. + * `keepSelection` - Clear the selection. + * `activateSelection` - Focus and click the selection node. -Stops any `findInPage` request for the `webContents` -with the provided `action`. +Stops any `findInPage` request for the `webContents` with the provided `action`. ```javascript -webContents.on('find-in-page-response', function(event, result) { +webContents.on('found-in-page', function(event, result) { if (result.finalUpdate) webContents.stopFindInPage("clearSelection"); }); -webContents.findInPage(1, "api"); -```. +const requestId = webContents.findInPage("api"); +``` ### `webContents.hasServiceWorker(callback)` diff --git a/docs/api/web-view-tag.md b/docs/api/web-view-tag.md index e317ef8eab1e..a65bc6063642 100644 --- a/docs/api/web-view-tag.md +++ b/docs/api/web-view-tag.md @@ -348,6 +348,36 @@ Executes editing command `replace` in page. Executes editing command `replaceMisspelling` in page. +### `.findInPage(text[, options])` + +* `text` String - Content to be searched, must not be empty. +* `options` Object (Optional) + * `forward` Boolean - Whether to search forward or backward, defaults to `true`. + * `findNext` Boolean - Whether the operation is first request or a follow up, + defaults to `false`. + * `matchCase` Boolean - Whether search should be case-sensitive, + defaults to `false`. + * `wordStart` Boolean - Whether to look only at the start of words. + defaults to `false`. + * `medialCapitalAsWordStart` Boolean - When combined with `wordStart`, + accepts a match in the middle of a word if the match begins with an + uppercase letter followed by a lowercase or non-letter. + Accepts several other intra-word matches, defaults to `false`. + +Starts a request to find all matches for the `text` in the web page and returns an `Integer` +representing the request id used for the request. The result of the request can be +obtained by subscribing to [`found-in-page`](web-view-tag.md#event-found-in-page) event. + +### `.stopFindInPage(action)` + +* `action` String - Specifies the action to take place when ending + [`.findInPage `](web-view-tag.md#webviewtagfindinpage) request. + * `clearSelection` - Translate the selection into a normal selection. + * `keepSelection` - Clear the selection. + * `activateSelection` - Focus and click the selection node. + +Stops any `findInPage` request for the `webview` with the provided `action`. + ### `.print([options])` Prints `webview`'s web page. Same with `webContents.print([options])`. @@ -499,6 +529,28 @@ webview.addEventListener('console-message', function(e) { }); ``` +### Event: 'found-in-page' + +Returns: + +* `result` Object + * `requestId` Integer + * `finalUpdate` Boolean - Indicates if more responses are to follow. + * `matches` Integer (Optional) - Number of Matches. + * `selectionArea` Object (Optional) - Coordinates of first match region. + +Fired when a result is available for +[`webview.findInPage`](web-view-tag.md#webviewtagfindinpage) request. + +```javascript +webview.addEventListener('found-in-page', function(e) { + if (e.result.finalUpdate) + webview.stopFindInPage("keepSelection"); +}); + +const rquestId = webview.findInPage("test"); +``` + ### Event: 'new-window' Returns: diff --git a/spec/fixtures/pages/content.html b/spec/fixtures/pages/content.html new file mode 100644 index 000000000000..e37ba34c1d33 --- /dev/null +++ b/spec/fixtures/pages/content.html @@ -0,0 +1,16 @@ +

+ Virtual member functions are key to the object-oriented paradigm, + such as making it easy for old code to call new code. + A virtual function allows derived classes to replace the implementation + provided by the base class. The compiler makes sure the replacement is + always called whenever the object in question is actually of the derived class, + even if the object is accessed by a base pointer rather than a derived pointer. + This allows algorithms in the base class to be replaced in the derived class, + even if users dont know about the derived class. + + class A { + public: + virtual void foo() {} + } + +

diff --git a/spec/webview-spec.coffee b/spec/webview-spec.coffee index 28b25a226617..c0578d05053b 100644 --- a/spec/webview-spec.coffee +++ b/spec/webview-spec.coffee @@ -390,3 +390,19 @@ describe ' tag', -> done() webview.src = "file://#{fixtures}/pages/audio.html" document.body.appendChild webview + + describe 'found-in-page event', -> + it 'emits when a request is made', (done) -> + requestId = null + listener = (e) -> + assert.equal e.result.requestId, requestId + if e.result.finalUpdate + assert.equal e.result.matches, 3 + webview.stopFindInPage "clearSelection" + done() + listener2 = (e) -> + requestId = webview.findInPage "virtual" + webview.addEventListener 'found-in-page', listener + webview.addEventListener 'did-finish-load', listener2 + webview.src = "file://#{fixtures}/pages/content.html" + document.body.appendChild webview From 61004f0e46cbeb4be7cf71dae36a13a1c463f39a Mon Sep 17 00:00:00 2001 From: Robo Date: Mon, 21 Dec 2015 18:24:55 +0530 Subject: [PATCH 3/3] fix cpplint warning --- atom/browser/api/atom_api_web_contents.cc | 1 - atom/common/native_mate_converters/blink_converter.h | 2 +- docs/api/web-contents.md | 2 +- docs/api/web-view-tag.md | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 995774376e96..037663db4758 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -49,7 +49,6 @@ #include "content/public/browser/site_instance.h" #include "content/public/browser/web_contents.h" #include "content/public/common/context_menu_params.h" -#include "native_mate/converter.h" #include "native_mate/dictionary.h" #include "native_mate/object_template_builder.h" #include "net/http/http_response_headers.h" diff --git a/atom/common/native_mate_converters/blink_converter.h b/atom/common/native_mate_converters/blink_converter.h index 5e715c631783..6a3601929214 100644 --- a/atom/common/native_mate_converters/blink_converter.h +++ b/atom/common/native_mate_converters/blink_converter.h @@ -17,7 +17,7 @@ struct WebFindOptions; struct WebFloatPoint; struct WebPoint; struct WebSize; -} +} // namespace blink namespace content { struct NativeWebKeyboardEvent; diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index 3d903a8414d8..f856b9229c1d 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -457,7 +457,7 @@ obtained by subscribing to [`found-in-page`](web-contents.md#event-found-in-page ### `webContents.stopFindInPage(action)` * `action` String - Specifies the action to take place when ending - [`webContents.findInPage `](web-contents.md#webcontentfindinpage) request. + [`webContents.findInPage`](web-contents.md#webcontentfindinpage) request. * `clearSelection` - Translate the selection into a normal selection. * `keepSelection` - Clear the selection. * `activateSelection` - Focus and click the selection node. diff --git a/docs/api/web-view-tag.md b/docs/api/web-view-tag.md index a65bc6063642..ea99358290b0 100644 --- a/docs/api/web-view-tag.md +++ b/docs/api/web-view-tag.md @@ -371,7 +371,7 @@ obtained by subscribing to [`found-in-page`](web-view-tag.md#event-found-in-page ### `.stopFindInPage(action)` * `action` String - Specifies the action to take place when ending - [`.findInPage `](web-view-tag.md#webviewtagfindinpage) request. + [`.findInPage`](web-view-tag.md#webviewtagfindinpage) request. * `clearSelection` - Translate the selection into a normal selection. * `keepSelection` - Clear the selection. * `activateSelection` - Focus and click the selection node.