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

Side by Side Diff: webkit/glue/glue_serialize.cc

Issue 10695107: Fix: file permissions when restoring a page with file inputs with selected files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « webkit/glue/glue_serialize.h ('k') | webkit/glue/glue_serialize_unittest.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "webkit/glue/glue_serialize.h" 5 #include "webkit/glue/glue_serialize.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/pickle.h" 9 #include "base/pickle.h"
10 #include "base/string_number_conversions.h"
10 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
11 #include "googleurl/src/gurl.h" 12 #include "googleurl/src/gurl.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebData.h" 13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebData.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h" 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebHTTPBody. h" 15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebHTTPBody. h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h" 16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSerialize dScriptValue.h" 17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSerialize dScriptValue.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" 18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" 19 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" 20 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 WebHTTPBody::Element element; 554 WebHTTPBody::Element element;
554 for (size_t i = 0; i < http_body.elementCount(); ++i) { 555 for (size_t i = 0; i < http_body.elementCount(); ++i) {
555 http_body.elementAt(i, element); 556 http_body.elementAt(i, element);
556 if (element.type == WebHTTPBody::Element::TypeFile) 557 if (element.type == WebHTTPBody::Element::TypeFile)
557 to_return.push_back(WebStringToFilePath(element.filePath)); 558 to_return.push_back(WebStringToFilePath(element.filePath));
558 } 559 }
559 } 560 }
560 return to_return; 561 return to_return;
561 } 562 }
562 563
564 std::vector<FilePath> FilePathsFromInputsInHistoryState(
565 const std::string& content_state) {
566 std::vector<FilePath> to_return;
567 // TODO(darin): We should avoid using the WebKit API here, so that we do not
568 // need to have WebKit initialized before calling this method.
569 const WebHistoryItem& item =
570 HistoryItemFromString(content_state, ALWAYS_INCLUDE_FORM_DATA, true);
571 if (item.isNull()) {
572 // Couldn't parse the string.
573 return to_return;
574 }
575 const WebVector<WebString>& document_state = item.documentState();
576 if (document_state.isEmpty())
577 return to_return;
578 // The first entry contains the version number of the document state. Check
579 // the version here, otherwise this might result in granting file permissions
580 // to wrong files.
581 if (std::string(document_state[0].utf8()).find(
582 "WebKit serialized form state version 5") == std::string::npos)
583 return to_return;
584
585 // For each document element, the vector contains the following entries:
brettw 2012/07/11 00:02:42 WE don't want to do this type of manual parsing wh
marja 2012/08/22 09:04:28 Done.
586 // - name
587 // - form control type
588 // - form key
589 // - number of additional fields
590 // - additional field 1
591 // - ...
592 // - additional field n
593 size_t i = 1; // Skip the first entry.
594 while (i + 3 < document_state.size()) {
595 int fields;
596 if (!base::StringToInt(std::string(document_state[i + 3].utf8()), &fields))
597 break;
598 if (i + 3 + fields >= document_state.size())
599 break;
600 if (document_state[i + 1] == "file") {
601 for (size_t j = i + 4; j < i + 4 + fields; j += 2) {
602 // For file inputs, the additional fields are:
603 // - file path
604 // - file name
605 to_return.push_back(WebStringToFilePath(document_state[j]));
606 }
607 }
608 // Jump to the next entry.
609 i += (4 + fields);
610 }
611 return to_return;
612 }
613
563 // For testing purposes only. 614 // For testing purposes only.
564 void HistoryItemToVersionedString(const WebHistoryItem& item, int version, 615 void HistoryItemToVersionedString(const WebHistoryItem& item, int version,
565 std::string* serialized_item) { 616 std::string* serialized_item) {
566 if (item.isNull()) { 617 if (item.isNull()) {
567 serialized_item->clear(); 618 serialized_item->clear();
568 return; 619 return;
569 } 620 }
570 621
571 // Temporarily change the version. 622 // Temporarily change the version.
572 int real_version = kVersion; 623 int real_version = kVersion;
573 kVersion = version; 624 kVersion = version;
574 625
575 SerializeObject obj; 626 SerializeObject obj;
576 WriteHistoryItem(item, &obj); 627 WriteHistoryItem(item, &obj);
577 *serialized_item = obj.GetAsString(); 628 *serialized_item = obj.GetAsString();
578 629
579 kVersion = real_version; 630 kVersion = real_version;
580 } 631 }
581 632
582 int HistoryItemCurrentVersion() { 633 int HistoryItemCurrentVersion() {
583 return kVersion; 634 return kVersion;
584 } 635 }
585 636
586 } // namespace webkit_glue 637 } // namespace webkit_glue
OLDNEW
« no previous file with comments | « webkit/glue/glue_serialize.h ('k') | webkit/glue/glue_serialize_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698