diff options
author | deepak.m1 <deepak.m1@samsung.com> | 2015-01-18 23:03:20 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-01-19 07:04:14 +0000 |
commit | 6313ce26ea190d5da88e4fe6473b693de37305e2 (patch) | |
tree | 806590b992fc43097ac82f3a2f859797fdb9f75f /pdf | |
parent | 6bac02f4ea0b4b632c108a96265d5e358664a7a9 (diff) | |
download | chromium_src-6313ce26ea190d5da88e4fe6473b693de37305e2.zip chromium_src-6313ce26ea190d5da88e4fe6473b693de37305e2.tar.gz chromium_src-6313ce26ea190d5da88e4fe6473b693de37305e2.tar.bz2 |
Fix for Navigation to relative fragments does not work correctly for OOP pdf case.
When #XXX is already present in the url and same #XXX is href
for navigation on selection href, then we should not add that
already present in the url then don't add this href.
BUG=447888
Review URL: https://codereview.chromium.org/830433002
Cr-Commit-Position: refs/heads/master@{#312075}
Diffstat (limited to 'pdf')
-rw-r--r-- | pdf/out_of_process_instance.cc | 55 | ||||
-rw-r--r-- | pdf/pdf_engine.h | 2 | ||||
-rw-r--r-- | pdf/pdfium/pdfium_engine.cc | 26 | ||||
-rw-r--r-- | pdf/pdfium/pdfium_engine.h | 2 |
4 files changed, 47 insertions, 38 deletions
diff --git a/pdf/out_of_process_instance.cc b/pdf/out_of_process_instance.cc index f9a7031..2f08ff9 100644 --- a/pdf/out_of_process_instance.cc +++ b/pdf/out_of_process_instance.cc @@ -136,6 +136,10 @@ const char kJSGetSelectedTextType[] = "getSelectedText"; const char kJSGetSelectedTextReplyType[] = "getSelectedTextReply"; const char kJSSelectedText[] = "selectedText"; +// List of named destinations (Plugin -> Page) +const char kJSSetNamedDestinationsType[] = "setNamedDestinations"; +const char kJSNamedDestinations[] = "namedDestinations"; + const int kFindResultCooldownMs = 100; const double kMinZoom = 0.01; @@ -849,42 +853,9 @@ void OutOfProcessInstance::ScrollToPage(int page) { void OutOfProcessInstance::NavigateTo(const std::string& url, bool open_in_new_tab) { - std::string url_copy(url); - - // Empty |url_copy| is ok, and will effectively be a reload. - // Skip the code below so an empty URL does not turn into "http://", which - // will cause GURL to fail a DCHECK. - if (!url_copy.empty()) { - // If |url_copy| starts with '#', then it's for the same URL with a - // different URL fragment. - if (url_copy[0] == '#') { - url_copy = url_ + url_copy; - } - // If there's no scheme, add http. - if (url_copy.find("://") == std::string::npos && - url_copy.find("mailto:") == std::string::npos) { - url_copy = std::string("http://") + url_copy; - } - // Make sure |url_copy| starts with a valid scheme. - if (url_copy.find("http://") != 0 && - url_copy.find("https://") != 0 && - url_copy.find("ftp://") != 0 && - url_copy.find("file://") != 0 && - url_copy.find("mailto:") != 0) { - return; - } - // Make sure |url_copy| is not only a scheme. - if (url_copy == "http://" || - url_copy == "https://" || - url_copy == "ftp://" || - url_copy == "file://" || - url_copy == "mailto:") { - return; - } - } pp::VarDictionary message; message.Set(kType, kJSNavigateType); - message.Set(kJSNavigateUrl, url_copy); + message.Set(kJSNavigateUrl, url); message.Set(kJSNavigateNewTab, open_in_new_tab); PostMessage(message); } @@ -1109,10 +1080,18 @@ void OutOfProcessInstance::DocumentLoadComplete(int page_count) { OnGeometryChanged(0, 0); } - pp::VarDictionary message; - message.Set(pp::Var(kType), pp::Var(kJSLoadProgressType)); - message.Set(pp::Var(kJSProgressPercentage), pp::Var(100)) ; - PostMessage(message); + pp::VarDictionary named_destinations_message; + pp::VarDictionary named_destinations = engine_->GetNamedDestinations(); + named_destinations_message.Set(pp::Var(kType), + pp::Var(kJSSetNamedDestinationsType)); + named_destinations_message.Set(pp::Var(kJSNamedDestinations), + pp::Var(named_destinations)); + PostMessage(named_destinations_message); + + pp::VarDictionary progress_message; + progress_message.Set(pp::Var(kType), pp::Var(kJSLoadProgressType)); + progress_message.Set(pp::Var(kJSProgressPercentage), pp::Var(100)); + PostMessage(progress_message); pp::VarDictionary bookmarksMessage; bookmarksMessage.Set(pp::Var(kType), pp::Var(kJSBookmarksType)); diff --git a/pdf/pdf_engine.h b/pdf/pdf_engine.h index a9f828e5..884daab 100644 --- a/pdf/pdf_engine.h +++ b/pdf/pdf_engine.h @@ -28,6 +28,7 @@ namespace pp { class InputEvent; +class VarDictionary; } const uint32 kBackgroundColor = 0xFFCCCCCC; @@ -269,6 +270,7 @@ class PDFEngine { virtual void SetScrollPosition(const pp::Point& position) = 0; virtual bool IsProgressiveLoad() = 0; + virtual pp::VarDictionary GetNamedDestinations() = 0; }; // Interface for exports that wrap the PDF engine. diff --git a/pdf/pdfium/pdfium_engine.cc b/pdf/pdfium/pdfium_engine.cc index eac9957..86485e0 100644 --- a/pdf/pdfium/pdfium_engine.cc +++ b/pdf/pdfium/pdfium_engine.cc @@ -2382,6 +2382,32 @@ int PDFiumEngine::GetNamedDestinationPage(const std::string& destination) { return dest ? FPDFDest_GetPageIndex(doc_, dest) : -1; } +pp::VarDictionary PDFiumEngine::GetNamedDestinations() { + pp::VarDictionary named_destinations; + for (unsigned long i = 0; i < FPDF_CountNamedDests(doc_); i++) { + base::string16 name; + unsigned long buffer_bytes; + FPDF_GetNamedDest(doc_, i, NULL, buffer_bytes); + size_t name_length = buffer_bytes / sizeof(base::string16::value_type); + if (name_length > 0) { + PDFiumAPIStringBufferAdapter<base::string16> api_string_adapter( + &name, name_length, true); + FPDF_DEST dest = FPDF_GetNamedDest(doc_, i, api_string_adapter.GetData(), + buffer_bytes); + api_string_adapter.Close(name_length); + if (dest) { + std::string named_dest = base::UTF16ToUTF8(name); + int page_number = GetNamedDestinationPage(named_dest); + if (page_number >= 0) { + named_destinations.Set(pp::Var(named_dest.c_str()), + pp::Var(page_number)); + } + } + } + } + return named_destinations; +} + int PDFiumEngine::GetFirstVisiblePage() { CalculateVisiblePages(); return first_visible_page_; diff --git a/pdf/pdfium/pdfium_engine.h b/pdf/pdfium/pdfium_engine.h index cf1fe052..bf3bff9 100644 --- a/pdf/pdfium/pdfium_engine.h +++ b/pdf/pdfium/pdfium_engine.h @@ -29,6 +29,7 @@ namespace pp { class KeyboardInputEvent; class MouseInputEvent; +class VarDictionary; } namespace chrome_pdf { @@ -81,6 +82,7 @@ class PDFiumEngine : public PDFEngine, virtual int GetNumberOfPages(); virtual pp::VarArray GetBookmarks(); virtual int GetNamedDestinationPage(const std::string& destination); + virtual pp::VarDictionary GetNamedDestinations(); virtual int GetFirstVisiblePage(); virtual int GetMostVisiblePage(); virtual pp::Rect GetPageRect(int index); |